Recently encountered an enumeration type, just by the way.
The base class of Enum Enum, which can be any integral type except Char. If you do not make a display declaration, the default is reshape (Int32).
declares an enum type :
<summary> ///color///</summary> public enum People {[Description ("Baby")] Baby = 0, [Description ("Child")] children = 5, [Description ("Youth")] Youth =, [Description ("Old Man") )] Old =
Enum is converted to String type:
(1) using the Object.ToString () method:
People.Baby.ToString ();
(2) using the static method of enum GetName:
Enum.getname (typeof (People), 0) Enum.getname (typeof (People), People.baby)
The string type is converted to an enum:
(1) The static method of using Enum, parse:
(people) Enum.parse (typeof (People), "children")
Enum is converted to an integer:
(1) Forced conversion
(int) People.youth; (byte) people.youth;//byte range of values, 0-255, caution some will overflow
convert int to enum:
(people) (60)
(people) Enum.toobject (typeof (People), 60)
Get an array of enum strings :
foreach (var item in Enum.getnames (typeof (People))) { Console.WriteLine (item);}
Determine if a shape is defined in an enum :
Enum.isdefined (typeof (People), 60);//returns TRUE or False
The result is:
Enum types in C #