using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication2 { //自定义枚举类型week,枚举定义在类里面或与类同级在命名空间里面 enum week : int//基本类型为int { //七个数据成员,用逗号隔开 mon = 1, tur = 2, wen = 3, thur = 4, fri = 5, sat = 6, sun = 7 } class Program { static void Main(string[] args) { week myweek;//声明一个枚举类型的变量 myweek = week.mon;//赋值,通过调用成员变量 Console.WriteLine(week.fri);//输出变量的成员变量 Console.WriteLine(Enum.GetName(typeof(week),3));//输出之对应的名称 //遍历week输出所有成员变量的值 foreach (var item in Enum.GetNames(typeof(week))) { Console.WriteLine(item); } Console.WriteLine(Enum.IsDefined(typeof(week),1));//判断某个值在枚举中是否有定义 Console.Read(); } } }