Enumerations
Create and utilize enumerations to define named constants and manage application state in C#.
We'll cover the following...
We'll cover the following...
C# allows us to create enumerations in addition to primitive data types. An enumeration represents a collection of logically related constants.
Suppose a method needs 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.
Enumerations definition
We can create an enumeration containing all days of the week to ensure the caller selects a valid, predefined constant.
An enumeration is declared using the enum keyword: