Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 614 Bytes

Time-specific-salutation.md

File metadata and controls

30 lines (23 loc) · 614 Bytes

Time-specific salutation

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