May 11, 2021 C#
Enumerals are a set of named integer constants. The enumerant type is declared using the enum keyword.
The C#enumeration is a value data type. In other words, enumeration contains its own values and cannot inherit or pass inheritance.
General syntax for declaring enumerations:
enum <enum_name>
{
enumeration list
};
Among them,
Each symbol in the enumeration list represents an integer value, a larger integer value than the symbol before it. By default, the value of the first enumeration symbol is 0. For example:
enum Days { Sun, Mon, tue, Wed, thu, Fri, Sat };
The following example demonstrates the use of enumeration variables:
using System;
namespace EnumApplication
{
class EnumProgram
{
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();
}
}
}
When the above code is compiled and executed, it produces the following results:
Monday: 1
Friday: 5