Enumerations
Create and use enums in C#.
We'll cover the following...
Declaration
In addition to primitive data types, it’s possible to create enumerations in C#. An enumeration represents a collection of logically related constants.
For example, we want our method to accept a day of the week as a parameter. We have several options:
- We could accept a string value (like
"Monday"
) - We could accept an integer that represents the day of the week (like
2
) - We could use enumerations
In our case, we’ll create an enumeration that holds all possible days of the week, so that the user has to choose a constant we provide. ...