Switch with enum : enum switch « Data Type « C# / CSharp Tutorial






using System;
public enum TimeOfDay {
    Morning = 0,
    Afternoon = 1,
    Evening = 2
}

class EnumExample {
    public static void Main() {
        WriteGreeting(TimeOfDay.Morning);

    }

    static void WriteGreeting(TimeOfDay timeOfDay) {
        switch (timeOfDay) {
            case TimeOfDay.Morning:
                Console.WriteLine("Good morning!");
                break;
            case TimeOfDay.Afternoon:
                Console.WriteLine("Good afternoon!");
                break;
            case TimeOfDay.Evening:
                Console.WriteLine("Good evening!");
                break;
            default:
                Console.WriteLine("Hello!");
                break;
        }
    }
}








2.39.enum switch
2.39.1.Enums as parameters
2.39.2.Pass enum to function
2.39.3.Switch with enum