Csharp Enum
# C# Enum
An enum is a set of named integer constants. Enum types are declared using the **enum** keyword.
C# enums are value types. In other words, enums contain their own values and cannot inherit or pass on inheritance.
## Declaring _enum_ Variables
The general syntax for declaring an enum:
enum { enumeration list };
where,
* _enum_name_ specifies the name of the enum type.
* _enumeration list_ is a comma-separated list of identifiers.
Each symbol in the enumeration list represents an integer value, an integer value greater than the one before it. By default, the value of the first enumeration symbol is 0. For example:
enum Days { Sun, Mon, tue, Wed, thu, Fri, Sat };
## Example
The following example demonstrates the usage of enum variables:
## Example
using System;
public class EnumTest
{
enum Day { Sun, Mon, Tue, Wed, Thu, Fri, Sat };
static void Main()
{
int x =(int)Day.Sun;
int y =(int)Day.Fri;
Console.WriteLine("Sun = {0}", x);
Console.WriteLine("Fri = {0}", y);
}
}
When the above code is compiled and executed, it produces the following result:
Sun = 0Fri = 5
YouTip