Enumerations in C#

An enumeration is used to represent a set of related values.
Example: Up-Down, North-South-East-West

An enumeration is defined using the enum keyword and a code block in which the various values are defined.
Here’s a simple example:
enum color

Once defined, an enumeration value can be used by specifying the enumeration type, a dot, and then the specific name desired:

color rainbow = color.Red;

The names within an enumeration are actually numeric values. By default, they are integers, whose value begins at zero.
You can modify both the type of storage used for these values and the values associated with a particular name.
Here’s an example, where a short is used to hold different coin values:
enum Coin: short{
Penny = 1, Nickel = 5, Dime = 10, Quarter = 25

Then, the names can be cast to their implementing value type:
short change = (short) (Coin.Penny + Coin.Quarter);

This will result in the value of change being 26.

It is also possible to do bitwise operations on enumerations that are given compatible:
enum Flavor{
Vanilla = 1, Chocolate = 2, Strawberry = 4, Coffee = 8

Flavor conePref = Flavor.Vanilla | Flavor.Coffee;