Enumeration is a named value which is used to allocate various constant values to a single variable. This makes the program more easier to understand and maintain. Enumeration is also having better error checking techniques which additional security.
An enumeration is defined by using enum keyword.
Syntax of enumeration is:-
enum enum_name
{
enumeration list
};
Enumeration contains it's own values, it can not inherit and also does not proceed inheritance.
Let us understand the enumeration with example:-
using System;
namespace enumprogram
{
public enum list { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }
class Program
{
static void Main(string[] args)
{
list day = list.Tuesday;
Console.WriteLine((int)day);
Console.ReadLine();
}
}
}
output= 1(Because tuesday values to the number 1)
0 Comment(s)