Enums enumeration is a value type. Data is directly stored in the stack, instead of being stored using reference and real data isolation.
(1) by default, the first variable in the enumeration is assigned 0, and the values of other variables are incremented in the defined order (, 3 ...), therefore, the following two code definitions are equivalent:
[Csharp]
Enum TrafficLight
{
Green,
Yellow,
Red
}
[Csharp]
Enum TrafficLight
{
Green = 0,
Yellow = 1,
Red = 2
}
(2) the names of enum-type variables cannot be the same, but the values can be the same. For example:
[Csharp]
Enum TrafficLight
{
Green = 0,
Yellow = 1, // Duplicate value, OK
Red = 1 // Duplicate value, OK
}
(3) if some members in the enum explicitly define the value but some do not, the value of the member who does not define the value is assigned progressively according to the value of the previous Member. For example:
[Csharp]
Enum LoopType
{
None, // value is 0
Daily, // value is 1
Weekly = 7,
Monthly, // value is 8
Yeayly, // value is 9
DayGap = 15,
WeekGap, // value is 16
MonthGap, // value is 17
YearGap // value is 18
}
(4) enum enumeration members can be used as bit flags and support bit operations (bit and, bit or so on), such:
[Csharp]
Enum CardDeckSettings: uint
{
SingleDeck = 0x01, // Bit 0
LargePictures = 0x02, // Bit 1
FancyNumbers = 0x04, // Bit 2
Animation = 0x08 // Bit 3
}
A hexadecimal number is used for bitwise operations and operations, which is very convenient.