14. Enums

An enum type is a distinct value type (§4.1) that declares a set of named constants.

The example

        enum Color        {                Red,                Green,                Blue        }

declares an enum type named Color with members Red, Green, and Blue.

14.1 Enum Declarations

An enum declaration declares a new enum type. An enum declaration begins with the keyword enum, and defines the name, accessibility, underlying type, and members of the enum.

    enum-declaration:            attributesopt enum-modifiersopt enum identifier enum-baseopt enum-body ;opt

    enum-base:            :  integral-type

    enum-body:            {  enum-member-declarationsopt }            {  enum-member-declarations , }

Each enum type has a corresponding ...

Get The C# Programming Language, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.