An enum provides a base class for an enumeration whose underlying type can be any integral type except Char. If you do not explicitly declare an underlying type, use Int32. Programming languages typically provide syntax to declare enumerations that consist of a set of named constants and their values. Note: The base type of an enumeration type is any integral type except Char, so the value of the enumeration type is an integer value. The Enum provides some useful static methods: (1) to compare the methods of enumerating instances of the class (2) to convert the value of the instance to its string representation (3A method that converts the string representation of a number to an instance of this class (4creates a method that specifies an instance of an enumeration and a value. Example:enumColors {Red, Green, Blue, Yellow}; Enum-String (1) using the Object.ToString () method: Values such as Colors.Green.ToString () are"Green"string; (2GetName and GetNames using the static method of enum: Public Static stringGetName (Type enumtype,object value) Public Static string[] GetNames (Type enumtype) For example: Enum.getname (typeof(Colors),3)) and Enum.getname (typeof(Colors), Colors.blue)) are the values of"Blue"Enum.getnames (typeof(Colors)) will return an array of enumerated strings. String-Enum (1using the static method of Enum, parse: Public StaticObject Parse (Type enumtype,stringvalue) For example: (Colors) Enum.parse (typeof(Colors),"Red") Enum-Int (1because the base type of the enumeration is an integral type other than Char, you can cast it. For example: (int) Colors.red, (byte) Colors.greenint-Enum (1you can cast an integral type to an enumeration type. Example: Colors color= (Colors)2, then color is Colors.blue (2) using the static method of the enum Toobject. Public StaticObject Toobject (Type enumtype,intvalue) For example: Colors color= (Colors) enum.toobject (typeof(Colors),2, then color is the method by which Colors.blue determines whether an integer is defined in an enumeration: Enum.isdefined Public Static BOOLIsDefined (Type enumtype,object value) For example: enum.isdefined (typeof(Colors), N))
C # enum,int,string Conversion of reciprocal conversions enumeration