C# enumerations are value data type. An enumeration is a set of named integer constants. An enumerated type is declared using the enum keyword.
The following is the syntax of enum.
enum <enum_name> {
enumeration list
};Let us see an example.
enum Vehicle { Car, Bus, Truck };The following is an example showing how to use enum keyword to define variable type.
Example
using System;
namespace Demo {
class Program {
enum Days { Sun, Mon, tue, Wed, thu, Fri, Sat };
static void Main(string[] args) {
int WeekdayStart = (int)Days.Mon;
int WeekdayEnd = (int)Days.Fri;
Console.WriteLine("Monday: {0}", WeekdayStart);
Console.WriteLine("Friday: {0}", WeekdayEnd);
Console.ReadKey();
}
}
}Output
Monday: 1 Friday: 5