Enumeration:
Enumeration provides the best way to define a set of named integral constants which we assigned to a variable by using the enum keyword before variable. For an instance, if we define a variable whose value will represent the name of the countries then we can declare enumeration in this way
enum CountryNames { Pakistan, Japan, Italy, Spain};
ENUM keyword
We use the enum keyword to declare an enumeration. The default type of each element in the enum is int. However, we can also assign other integral numeric type by using a colon. For example,
enum Volume :byte{ Low =20,Medium =24, High =33}
The following code will show the comparison of enumeration.
CODE:
using System;
class Program
{
enum Age
{
Teenager = 14,
Adult = 18,
Old = 50
}
static void Main(string[] args)
{
Age Ali = Age.Teenager;
Age Hassan = Age.Adult;
if (Ali < Hassan)
Console.WriteLine("Ali is younger than Hassan");
else
Console.WriteLine("Ali is not younger than Hassan");
Console.ReadLine();
}
}