Time-specific salutation

November 9, 2016 ยท View on GitHub

Generates a simple greeting based on the time of day.

public static string Salutation()
{
    var now = System.DateTime.Now;
    return
        now.Hour < 12 ? "Good morning" :
        now.Hour < 18 ? "Good afternoon" :
        now.Hour < 21 ? "Good evening" :
        /* otherwise */ "Good night";
}

Usage

 System.Diagnostics.Debug.WriteLine(Salutation());

See also

DateTime
?: operator