How to Create Enum in C#


Enums are value types and they store list of strongly type constants. You can create enum in C# as follows:

enum WeekDays 
{
    Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
}

 

 

About author


User avatar

Waqas Anwar

Founder of EzzyLearning.com, Senior Consultant, Microsoft .NET and Web Technologies

Comments 2

user
Nice Guy
  • 07 September 2009

I want to know, How can I attach this enum with combo box in C# form. Please reply me.

Waqas Anwar
Waqas Anwar
  • 07 September 2009

Suppose you have enum like below.

public enum WeekDays
{
Mon, Tue, Wed, Thu, Fri, Sat, Sun
}


You can bind it with combobox as follows:

comboBox1.DataSource = Enum.GetValues(typeof(WeekDays));

Add Comment