blog

Home / DeveloperSection / Blogs / Enumeration in C#

Enumeration in C#

Amit Singh5922 01-Jan-2011

The enum keyword is used to declare an enumeration, a distinct type consisting of a set of named constants called the enumerator list. It is user defined data types. Every enumeration type has an underlying type, which can be any integral type except char. The default underlying type of the enumeration elements is int. By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1

How use enum keyword in our program


Example 1:


enum Days { Sat = 1, Sun, Mon, Tue, Wed, Thu, Fri }; 
protected void Page_Load(object sender, EventArgs e)
{ 
   int x = (int)Days.Sun;
   Response.Write(x);
}

Enums have these benefits:

·    They restrict the values that the enum variable can take.

·    They force you to think about all the possible values that the enum

can take.

·   They are a constant rather than a number, increasing readability of

the source code

you can also read these related post

https://www.mindstick.com/Articles/11950/enumeration-in-c-sharp


Updated 18-Sep-2014

Leave Comment

Comments

Liked By