Enumeration, typically used to customize some static variables, with keys and values.
such as Audit status:
public enum enumstate{
Pending review = 1, technology audited = 2, financial audited = 3, Mister Audited =4
}
This allows you to use enumerations for code operations instead of using strings.
Get string: enumstate. Technology has been audited. ToString ()
Get value: (int) enumstate. Technology audited
Binding in HTML. Loop Enumeration
@foreach (var name in Enum.getnames (typeof (Enumstate)))
{
int key = (int) (enumstate) Enum.parse (typeof (Enumstate), name);//Get enumeration by value
<option value= "@key" > @name </option>
}
However, enumerations cannot be string switch, as long as int is judged.
Enumstate State;
Switch (state) {
case (int) enumstate. Technology has been audited:
Break
}
The greatest benefit of using enumerations is that the enumeration is modified, and the other places are modified to ensure consistency and ease of use.
Experience Summary 40--c# Enumeration