Enum or EnumerationEnumeration is a user-defined data type in C# language. Enumeration is used to assign names to constants which makes it easy to access constants in a program. There is a keyword enum that gets used to declare Enumeration. You can declare or define integer enums, characters, and boolean in Enumeration.
enum enum_name{const1, const2, const3, const4…………….., constn};
The enum keyword is also used to declare or define the enum type variables. Two ways are using which you can declare or define this variable.
In enumeration elements are also accessed and stored in a manner. Like, enum num{One, Two, Three};
In the above example, the default value of One is 0 and 1 is of Two to access that element using that specific value. If we want to change these values, then we can change it
After this, the values are changed. You can access One using 1 and Two using 2, and this method helps to access elements easily throughout the program.
Enums get used when we want a fixed valued variable in the whole program, and we can set the values in the enum and access them.
|