---
title: "Enumeration in c#"  
description: "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 defi"  
author: "Amit Singh"  
published: 2011-01-01  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/329/enumeration-in-c-sharp  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# Enumeration in c#

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 to 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);}
```

##### Example 2:

##### \

In this example we store the enum data in dropdown list

```
public enum cricketRank{     India = 1,     SriLanka = 2,     Pakistan = 3,     SouthAfrica = 5,     Englan = 6,}       protected void Page_Load(object sender, EventArgs e){    if (!IsPostBack)  {    //Store the name of country in string type array     string[] names =  Enum.GetNames(typeof(cricketRank));    //Get the values from countryrank enum     var values = (cricketRank[])Enum.GetValues(typeof(cricketRank));     for (int i = 0; i < names.Length; i++)      DropDownList1.Items.Add(new ListItem(names[i], values.ToString()));  }}
```

##### Output:

![Enumeration in c#](https://www.mindstick.com/mindstickarticle/ade257fc-7058-4f60-a0fe-85c7ca52f004/images/fa1d3c2b-8632-4714-b43d-4cf4ca681d38.png)

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

---

Original Source: https://www.mindstick.com/articles/329/enumeration-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
