1. technical definitions of enumeration:
[Nature] [modifier] enum identifier [: base type] {enumeration list };
2. Common examples: (separated by commas)
[Csharp]
Enum Temperatures
{
SMALL,
LARGE = 5
}
Note:
1. The default base type is int, but ushort and long can be used at will, except for char. The data is a constant and cannot be changed. The preceding example is equivalent to const int SMALL = 0.
2. to display the value of an enumerated constant, You need to convert the constant to its underlying type. The above example should be converted to the int type.
3. Each constant in the enumeration corresponds to a value. The preceding example is an integer. If this parameter is not set, the enumeration starts from 0, and the next one is the first one plus 1. The above SMALL is 0, and LARGE is 5.
4. The conversion between the enumerated type and the integer type needs to be performed explicitly.
5. In C ++, the enumerated type must be assigned an integer, but the promote can be used as an integer to assign a value to the integer.
6. The base types include byte, sbyte, short, ushort, int, uint, long, And ulong.
3. Example:
[Csharp]
System. Console. WriteLine ("display SMALL value: {0}", (int) Temperatures. SMALL );
This article aims to popularize knowledge. If you find it helpful,
Please click the top word below to show more startup programmers