enums枚举是值类型,数据直接存储在栈中,而不是使用引用和真实数据的隔离方式来存储。
(1)默认情况下,枚举中的第一个变量被赋值为0,其他的变量的值按定义的顺序来递增(0,12,3...),因此以下两个代码定义是等价的:
- enum TrafficLight
- {
- Green,
- Yellow,
- Red
- }
- enum TrafficLight
- {
- Green = 0,
- Yellow = 1,
- Red = 2
- }
- enum TrafficLight
- {
- Green = 0,
- Yellow = 1, // Duplicate value, OK
- Red = 1 // Duplicate value, OK
- }
- 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
- }
- enum CardDeckSettings : uint
- {
- SingleDeck = 0x01, // Bit 0
- LargePictures = 0x02, // Bit 1
- FancyNumbers = 0x04, // Bit 2
- Animation = 0x08 // Bit 3
- }