1.

What is enum in C#?

Answer»

Enum is a primitive data type in C# used to define numeric constants in the .NET framework. Starting from 0, all the elements of the enum are given constant values, each increasing by 1.

For example, if we declare an enum for days of the week, the first element (Sunday) will get the value 0, the next element (Monday) will get the value 1, and so on till Saturday, which will get the value 6.

enum daysOfWeek { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };

To access any element, all you need to do is just pass the value of the element alongside enum’s variable, such as:

daysOfWeek[5]; // Will give the value Friday


Discussion

No Comment Found