首页 > 代码库 > enum

enum

//枚举类型是一种的值类型,它用于声明一组命名的常数。 //(1)枚举的声明:枚举声明用于声明新的枚举类型。 访问修辞符 enum 枚举名:基础类型 {     枚举成员 } //示例: public enum TimeofDay:uint {     Morning,     Afternoon,     Evening } //Morning的值为0,Afternoon的值为1,Evening的值为2。 class Test {     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;         }     }     static void Main()     {         WriteGreeting(TimeofDay.Morning);         WriteGreeting(TimeofDay.Evening);         WriteGreeting(TimeofDay.Afternoon);     } }

 

enum