C # Enumeration

Source: Internet
Author: User
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. collections; namespace consoleapplication1 {// enumeration Declaration: Access rhetoric Enum enumeration name: Basic Type Public Enum enumname: int // This int can omit {enumeration member} // the basic type must be able to represent all enumeration values defined in this enumeration. Enumeration declaration can explicitly declare the byte, sbyte, short, ushort, Int, uint, long, or ulong types as the corresponding basic types. The enumeration declaration without explicitly declaring the basic type means that the corresponding basic type is int. // The default basic type of enumeration elements is int. By default, the value of the first enumeration number is 0, and the value of each enumeration number increases by 1. Enum days {sat, sun, Mon, Tue, wed, Thu, Fri}; then // The default value is Enum days {0, 1, 2, 3, 4, 5, 6 }, if you want to set the default value to 1, you must start with Enum days {stat = 1, Sun = 2 ,.....} // The enumerated member is the name constant of the enumerated type. Any two enumeration members cannot have the same name. Each enumerated member has an associated constant value. The type of this value is the basic type of enumeration. The constant value of each enumeration member must be within the range of the basic Enumeration type. Enum Gender: uint {// male =-3, female =-2, unkown =-1 // generate a compile-time error, the reason is that the common values-1,-2, and-3 are not in the range of the basic integer uint. }; // Defines an enumeration. This enumeration has three values: moning, afternoon, evening Enum timeofday {moning, afternoon, evening}; // The value of morning is 0, the afternoon value is 1, and the evening value is 2. Class program {public static string Week (timeofday Str) // defines a week method, which has a timeofday parameter STR {string result = string. empty; Switch (STR) {// timeofday. the default value of moning is 0 case timeofday. moning: Result = "Morning"; break; Case timeofday. afternoon: result = "Afternoon"; break; Case timeofday. evening: Result = "Evening"; break;} return result;} static void main (string [] ARGs) {string S = program. week (timeofday. moning); console. writeline (s); // output the morning console. readkey ();}}}

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.