Enumeration instance Analysis

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.