13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 21 Enums21. EnumsAn enum type is a distinct type that declares a set of named constants. [Example: The exampleenum Color{Red,Green,Blue}declares an enum type named Color with members Red, Green, and Blue. end example]21.1 Enum declarationsAn enum declaration declares a new enum type. An enum declaration begins with the keyword enum, anddefines the name, accessibility, underlying type, and members of the enum.enum-declaration:attributes opt enum-modifiers opt enum identifier enum-base opt enum-body ; optenum-base:: integral-typeenum-body:{ enum-member-declarations opt }{ enum-member-declarations , }Each enum type has a corresponding integral type called the underlying type of the enum type. Thisunderlying type must be able to represent all the enumerator values defined in the enumeration. An enumdeclaration may explicitly declare an underlying type of byte, sbyte, short, ushort, int, uint, longor ulong. [Note: char cannot be used as an underlying type. end note] An enum declaration that does notexplicitly declare an underlying type has an underlying type of int.[Example: The exampleenum Color: long{Red,Green,Blue}declares an enum with an underlying type of long. end example] [Note: A developer might choose to use anunderlying type of long, as in the example, to enable the use of values that are in the range of long but notin the range of int, or to preserve this option for the future. end note]21.2 Enum modifiersAn enum-declaration may optionally include a sequence of enum modifiers:enum-modifiers:enum-modifierenum-modifiers enum-modifier293

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!