using System; using System.Collections.Generic; using System.Text; //枚举的定义及其简单运用 namespace interfaceDemo { //枚举定义一组特定值的数据类型,第一个值如果没有定义则默认为0,依次递增 //如果定义了某个特定的值,则自动加1,在默认情况下,枚举中的每个元素类型都是int类型 class TestEnum { enum WeekDay//声明枚举 { Sunday, Monday, Tuesday, Wednesday, Thurday, Friday, Saturday } static void CheckDay(WeekDay day) { switch (day) { case WeekDay.Sunday://使用枚举值 Console.WriteLine("星期日"); break; case WeekDay.Monday: Console.WriteLine("星期一"); break; case WeekDay.Tuesday: Console.WriteLine("星期二"); break; case WeekDay.Wednesday: Console.WriteLine("星期三"); break; case WeekDay.Thurday: Console.WriteLine("星期四"); break; case WeekDay.Friday: Console.WriteLine("星期五"); break; case WeekDay.Saturday: Console.WriteLine("星期六"); break; default: Console.WriteLine("输入有误"); break; } } static void Main(string[] args) { CheckDay(WeekDay.Monday); CheckDay((WeekDay)4);//将数字强制转换为枚举值 Console.ReadLine(); } } } //输出: //星期一 //星期四