C#枚举类型举例


using System;
namespace Test
{
    public enum TimeOfDay
    {
        Morning = 0,
        Afternoon = 1,
        Evening = 2
    }
    public class Student
    {
        static void Main()
        {
            WriteGreeting(TimeOfDay.Morning);
        }
        static void WriteGreeting(TimeOfDay day)
        {
            switch(day)
            {
                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;

            }
        }
    }
}