1. What is enumeration?
A: enumeration is a type defined by a programmer. It is the same as a class or structure.
Note: 1> like the structure, enumeration is a value type. Therefore, data is directly stored instead of being separated and stored as references and data. Enumeration is stored in the stack.
2> there is only one type of enumeration member: the named integer constant.
3> Each Enumeration type has an underlying Integer type. The default value is int. The compiler assigns the first member 0 and assigns one more value to each subsequent member than the previous one.
2. Examples of enumeration in stack arrangement?
Class Program
{
Static voidMain (string [] args)
{
TrafficLight t1 = TrafficLight. Green;
TrafficLight t2 = TrafficLight. Yellow;
TrafficLight t3 = TrafficLight. Red;
Console. WriteLine ("{0}, {1}", t1, (int) t1 );
Console. WriteLine ("{0}, {1}", t2, (int) t2 );
Console. WriteLine ("{0}, {1}", t3, (int) t3 );
Console. ReadKey ();
}
}
Enum TrafficLight
{
Green,
Yellow,
Red
}
The output result of the program is:
Green, 0
Yellow, 1
Red, 2
3. How does one supplement enumeration?
Because enumeration members are constants, they can be accessed even if they do not have variables of this enumeration type. The enumerated type names are followed by one vertex and member names.
Sample Code:
Class Program
{
Static voidMain (string [] args)
{
Console. WriteLine ("{0}", TrafficLight. Green );
Console. WriteLine ("{0}", TrafficLight. Yellow );
Console. WriteLine ("{0}", TrafficLight. Red );
Console. ReadKey ();
}
}
Enum TrafficLight
{
Green,
Yellow,
Red
}
Program output result:
Green
Yellow
Red
The author's wheat forever.