Changes between Version 3 and Version 4 of Enum
- Timestamp:
- 12/01/10 06:07:19 (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Enum
v3 v4 4 4 By default the underlying type of the enumeration elements is int and the first enumerator 5 5 has the value 0 with the value of each successive enumerator increased by 1.[[BR]] 6 Enumerators can have initiali zers to override the default values.6 Enumerators can have initialisers to override the default values. 7 7 8 8 In Cobra an enumeration is declared with the '''enum''' keyword followed by the enumeration name.[[BR]] 9 As this is a type the name must start with an uppercase letter.[[BR]] 10 Enumeration element names (with optional initialiser values) follow indented on subsequent lines. 9 As this is a type the enum name must start with an uppercase letter.[[BR]] 10 Enumeration element names (with optional initialiser values) follow individually on subsequent lines each equally indented 11 or with multiple comma separated on the same line. 12 13 {{{ 14 #!cobra 15 enum States 16 Init 17 Valid 18 Working 19 Dead 20 21 enum Tasks 22 ChopWood, CarryWater 23 Enlightenment 24 }}} 11 25 12 26 Emumerations are referenced by the Enumeration class name dotted with the enumeration element name[[BR]] 13 27 or like a constructor call: {{{enumName(enumElementName) }}}. 28 29 {{{ 30 #!cobra 31 e = MyEnum.Start 32 e1 = MyEnum(Start) 33 }}} 14 34 15 35 Multiple elements can be or'd together by specifying multiple elementNames comma separated … … 49 69 yesterday = Day(Thu) 50 70 weekend = Days(Sat, Sun) 71 72 isWeekend = today in [Days.Sat, Days.Sun] # explicit test enum member inclusion 73 74 75 enum OtherDays 76 Mon, Tue, Wed, Thu, Fri 77 Sat, Sun 51 78 }}} 52 79 53 See the effect of System.!FlagsAttribute on an enum 80 == Platform == 81 On .Net see the effect of System.!FlagsAttribute on an enum 54 82 {{{ 55 83 #!cobra … … 66 94 print options 67 95 print options to int 96 assert (options & CarOptions.SunRoof) == CarOptions.SunRoof # bitwise test combined options 68 97 69 98 /# Output is