classenumapp{//declares an enumeration type weekday, the base class is int, and the access scope is public Public enumWeekday {Sun, Mon, Tue, Wed, Thu, Fri, Sat} Public Static voidMain () {//declaring a variable with an enumeration type weekday and assigning an initial valueWeekday WD1 =Weekday.mon; Console.WriteLine ("Weekly working days starting with {0}", WD1); Weekday WD2=Weekday.fri; Console.WriteLine ("end to {0}", WD2); //enumeration Type variables are used to calculateConsole.WriteLine ("{0} business days per week", wd2-wd1); Console.WriteLine (); //enum type variables as arguments to functionsConsole.WriteLine ("after Mon is {0}", NextDay (Weekday.mon)); Console.WriteLine (); //using the enumeration type's GetNames () method foreach(stringS1inchWeekday.getnames (typeof(Weekday))) {Console.Write (S1+" "); } Console.WriteLine ("\ n"); //to read the value of an enumeration type variable from the command lineConsole.Write ("What's the day of the week?"); Weekday WD3= (Weekday) weekday.parse (typeof(Weekday), Console.ReadLine ()); Console.WriteLine ("tomorrow is {0}", NextDay (WD3)); Console.WriteLine (); //comparing values of enumerated typesConsole.Write ("What 's the day of physical education?"); WD1= (Weekday) weekday.parse (typeof(Weekday), Console.ReadLine ()); Console.Write ("physical test on the day of the week?"); WD2= (Weekday) weekday.parse (typeof(Weekday), Console.ReadLine ()); if(Wd1.compareto (wd2) = =0) {Console.WriteLine ("bad, on the same day. "); } Else{Console.WriteLine ("No , it's not the same day."); } } //function: Get the next day (days of the week)//Parameters://WD: Enum type weekday//return value: Enum type weekday Public StaticWeekday NextDay (Weekday wd) {Weekday wdnext; if(WD = =Weekday.sat) {Wdnext=Weekday.sun; } Else{Wdnext=wd+1; } returnWdnext; }}
_14__enum Day of the week