using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.Data; namespace 枚举 { class Program { public enum Week { sum=0,Mon=1,Tue=2,Wed=3,thr=4,Fri=5,sat=6 } static void Main(string[] args) { //获取代表星期几的返回值;因为今天是星期二所以返回值是2 int i= (int)(DateTime.Now.DayOfWeek); switch (i) { //如果返回的值与枚举元素对应的值相等,就输出今天是星期几 case (int)Week.sum: Console.WriteLine("星期日"); break; case (int)Week.Mon: Console.WriteLine("星期一"); break; case (int)Week.Tue: Console.WriteLine("星期二"); break; case (int)Week.Wed: Console.WriteLine("星期三"); break; case (int)Week.thr: Console.WriteLine("星期四"); break; case (int)Week.Fri: Console.WriteLine("星期五"); break; case (int)Week.sat: Console.WriteLine("星期六"); break; } Console.WriteLine(i);//输出2,因为今天是星期二,所以(int)DateTime.Now.DayOfWeek的返回值是2 Console.ReadKey(); } } }
原文:http://blog.csdn.net/fanbin168/article/details/24307863