= Enumeration = An enumeration is a distinct type consisting of a set of named constants (enumerator list, enumeration elements). [[BR]] By default the underlying type of the enumeration elements is int and the first enumerator has the value 0 with the value of each successive enumerator increased by 1.[[BR]] Enumerators can have initializers to override the default values. In Cobra an enumeration is declared with the '''enum''' keyword followed by the enumeration name.[[BR]] As this is a type the name must start with an uppercase letter.[[BR]] Enumeration element names (with optional initialiser values) follow indented on subsequent lines. Emumerations are referenced by the Enumeration class name dotted with the enumeration element name[[BR]] or like a constructor call: {{{enumName(enumElementName) }}}. Multiple elements can be or'd together by specifying multiple elementNames comma separated within the constructor-like call. == Grammar == {{{ #!cobra enum [ is ] [ has ] [ of ] [ ] [ = ] ... e = . e1 = ([, ...]) }}} == Platform == == Examples == {{{ #!cobra enum Days """In this enumeration, Sat is 0, Sun is 1, Mon is 2, and so forth.""" Sat Sun Mon Tue Wed Thu Fri class UseDays def main is shared today = Days.Fri yesterday = Day(Thu) weekend = Days(Sat, Sun) }}} See the effect of System.!FlagsAttribute on an enum {{{ #!cobra enum CarOptions has Flags SunRoof = 0x01 Spoiler = 0x02 FogLights = 0x04 TintedWindows = 0x08 class FlagTest def main is shared options = CarOptions(SunRoof,FogLights) print options print options to int /# Output is SunRoof, FogLights 5 Without 'has Flags' on enum CarOptions 5 5 #/ }}} == Notes == It is suggested all enumerations have an element whose value is 0.[[BR]] If this is in addition to the default starting point of values it should be named '''None'''. == See Also == [http://msdn.microsoft.com/en-us/library/sbbt4032%28VS.80%29.aspx enum(C# Reference)] [wiki:LanguageTopics Back to LanguageTopics]