int hour = DateTime.Now.Hour;
ViewData["greeting"] = (hour < 12 ? "Good morning" : "Good afternoon");
Sorry for the noob question, but the ASP.NET MVC book I’m currently reading assumes that I already know C# (but I don’t).
I understand the first part – it assigns current date and time to the hour variable. But I am lost on the 2nd line. What are those <, ?, : symbols for? ViewData[“greeting”] is this an array of some sorts?
Thanks!
If the hour is less than 12, ViewDate[“greeting”] is assigned a value of “Good morning”. Otherwise, it is assigned a value of “Good afternoon”.
The ?: bit is a conditional operator. MSDN gives a good description: