Enumerations are a type of C # programming language that are of the same level as classes, structs, sealed classes, distribution classes, delegates, events, and abstractions.
The enumeration itself can have modifiers, but the members of the enumeration are always public and cannot have access modifiers. Modifiers of the enumeration itself can only use public and internal.
Enumerations are value types, implicitly inherited from System.Enum, and cannot be modified manually.
Enumeration members cannot be the same, but the value of an enumeration can be the same, by default, the first variable in the enumeration is assigned a value of 0, the value of the other variable is incremented in the order defined (0,12,3 ...), if some member of the enum explicitly defines the value, and the part does not, Then a member that does not define a value is incremented by the value of the previous member.
Common methods:
Enumeration conversions:
Enum-->string:
1. Use the Object.ToString () method: The value of Colors.Green.ToString () is a "Green" string;
2. The static method of using the Enum GetName and GetNames: for example: Enum.getname (typeof (Colors), 3)) and Enum.getname (typeof (Colors), colors.blue) are "Blue"
Enum-->int:
Because the base type of the enumeration is an integral type other than Char, you can cast it.
For example: (int) colors.red, (byte) colors.green
String-->enum:
public static Object Parse (Type enumtype,string value)
For example: (Colors) Enum.parse (typeof (Colors), "Red")
Int-->enum:
You can cast an integral type to an enumeration type.
For example: Colors color = (Colors) 2, then color is Colors.blue
method to determine whether an integral type is defined in an enumeration: enum.isdefined
public static bool IsDefined (Type enumtype,Object value)
Example: enum.isdefined (typeof (Colors), 3))
Enumeration traversal:
foreach (intinenum.getvalues(typeof(ItemCode))) {
" " + Good);}
C # enum enum