118
Enum Constant Values
There is usually no need to know the actual constant values that the enum
constants
represent, but sometimes it can be useful. By default, the first
element has the value 0, and each successive
element has one value
higher.
enum State
{
Run, // 0
Wait, // 1
Stop // 2
};
These default values can be overridden by assigning values to the
constants. The values can be computed from an expression and they do
not have to be unique.
enum State
{
Run = 0, Wait = 3, Stop = Wait + 1
};
Enum Constant Type
The underlying type of the constant elements is implicitly specified as int,
but this can be changed by using a colon after the enumeration’s name
followed by the desired integer type.
enum MyEnum : byte {};
Chapter 20 enum