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.
Each enum type has a corresponding integral type called the underlying type of the enum type. This underlying type can represent all the enumerator values defined in the enumeration. An enum declaration may explicitly declare an underlying type of byte
, sbyte
, short
, ushort
, int,
uint,
long
or ulong
. Note that char
cannot be used as an underlying type. An enum declaration that does not explicitly declare an underlying type has an underlying type of int
.
The example
enum Color: long { Red, Green, Blue }
declares an enum with an underlying type of long
. A developer might choose to use an underlying type of long
, as in the example, to enable the use of values that are in the range of long
but not in the range of int
, or to preserve this option for the future.