One. Enumeration:
- Declaration of enum: enum A {A, B, c};
- An enum declaration differs from an array in that it can only be declared outside the main () method body and can be called in Main ().
- an enum can access an enumerated value by adding an enumeration name to the enumerated element. Cases:
int i = (int) a.a Public enumSun//defining enum Types{Monday=1,//do not write, the default is 0,1,2,3,4 ...Tuesday//It's just that the number starts to increment. Enumeration values can be the sameWednesday, Thursday, Friday, Saturday, Sunday}Static voidMain (string[] args) {Console.WriteLine ("to enter the test for the enumeration:"); Console.WriteLine ("*******************************************"); Console.WriteLine ("* Please enter 1--7 to test (8 for exit): *"); Console.WriteLine ("*******************************************"); intDay ; while(true)//This type of writing is more relevant in ASP.{Console.Write ("Please enter a number test:"); int. TryParse (Console.ReadLine (), outDay);//conversion Failure Day returns to "0" if(Day = =0) {Console.WriteLine ("the number entered is not legal!! Please enter 1--7 to test (8 for exit)"); } if(Day >8|| Day <0)//programming as far as possible to make their own procedures rigorous, here to determine the value of illegal{Console.WriteLine ("the number entered is not within the range, please enter 1--7 to test (8 for exit)"); } if(Day = =8)//termination conditions for exit{Console.WriteLine ("Successful exit Loop");//Successful exit Loop Break;//the code after break will not be executed.Console.WriteLine ("Exit Loop");//This code does not execute } Switch(Sun) Day)//string that corresponds to the enumeration value: (Sun) Day content is the string corresponding to the enumeration value { CaseSun. Monday: Console.WriteLine ("this is Monday ."); Break; CaseSun. Tuesday: Console.WriteLine ("this is Tuesday ."); Break; CaseSun. Wednesday: Console.WriteLine ("this is Wednesday ."); Break; CaseSun. Thursday: Console.WriteLine ("this is Thursday ."); Break; CaseSun. Friday: Console.WriteLine ("this is Friday ."); Break; CaseSun. Saturday: Console.WriteLine ("this is Saturday ."); Break; CaseSun. Sunday: Console.WriteLine ("this is Sunday ."); Break; }} console.readkey ();}
Run:
Enumeration instance Analysis