demilationcoder
Junior Member
- Jun 1, 2021
- 138
- 38
If you are able to use C# 9+ as the language version, give the following a try.
I admit it is "cryptic" like the Kotlin example shared above, but I wanted to show it because it is one of the capabilities of the language.
C#:
string greeting = DateTime.Now.Hour switch
{
>= 5 and < 12 => "Good Morning",
>= 12 and < 17 => "Good Afternoon",
>= 17 and < 21 => "Good Evening",
_ => "Good Night"
};
Console.WriteLine(greeting);
I admit it is "cryptic" like the Kotlin example shared above, but I wanted to show it because it is one of the capabilities of the language.