本文主要是介绍_14__enum___Weekday得到某日的下一日(星期几),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
// 声明一个枚举类型Weekday,基类为int,访问范围为publicpublic enum Weekday{Sun, Mon, Tue, Wed, Thu, Fri, Sat}
判断方法
// 功能: 得到某日的下一日(星期几)// 参数:// wd : 枚举类型Weekday// 返回值: 枚举类型Weekdaypublic static Weekday NextDay(Weekday wd){Weekday wdnext;if (wd == Weekday.Sat){wdnext=Weekday.Sun;}else{wdnext=wd+1;}return wdnext;}
public static void Main(){// 用枚举类型Weekday声明变量并赋初值Weekday wd1 = Weekday.Mon;Console.WriteLine("每周的工作日从{0}开始",wd1);Weekday wd2=Weekday.Fri;Console.WriteLine("到{0}结束",wd2);// 枚举类型变量用于计算Console.WriteLine("每周有{0}个工作日", wd2-wd1);Console.WriteLine();// 枚举类型变量作为函数的参数Console.WriteLine("Mon之后是{0}",NextDay(Weekday.Mon));Console.WriteLine();// 使用枚举类型的GetNames()方法foreach(string s1 in Weekday.GetNames(typeof(Weekday))){Console.Write(s1+" ");}Console.WriteLine("\n");// 从命令行读取枚举类型变量的值Console.Write("今天是星期几? ");Weekday wd3=(Weekday)Weekday.Parse(typeof(Weekday),Console.ReadLine());Console.WriteLine("明天是{0}",NextDay(wd3));Console.WriteLine();// 比较枚举类型的值Console.Write("体育课在星期几? ");wd1=(Weekday)Weekday.Parse(typeof(Weekday),Console.ReadLine());Console.Write("物理试验在星期几? ");wd2=(Weekday)Weekday.Parse(typeof(Weekday),Console.ReadLine());if(wd1.CompareTo(wd2) == 0){Console.WriteLine("糟糕,在同一天。");}else{Console.WriteLine("没事,不在同一天");}}
这篇关于_14__enum___Weekday得到某日的下一日(星期几)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!