- Back to Home »
- C#.NET »
- C#.NET Enum
Posted by :
Sudhir Chekuri
Saturday, 9 January 2016
Enum stands for enumeration. It makes programs cleaner and easier to read. It also causes no slowdown at runtime.
An enumeration is a set of named integer constants. An enumerated type is declared using the enum keyword.
C# enumerations are value data type. In other words, enumeration contains its own values
Example program for enum
Program
Output
True
An enumeration is a set of named integer constants. An enumerated type is declared using the enum keyword.
C# enumerations are value data type. In other words, enumeration contains its own values
Example program for enum
Program
using System;
namespace Enum
{
class Program
{
enum WorkingDays
{
Monday,
Tuesday,
Wednesday,
Thursday,
Friday
};
static void Main()
{
// ... An enum local variable.
WorkingDays value = WorkingDays.Thursday;
// ... Test against known
Importance values.
if (value == WorkingDays.Friday)
{
Console.WriteLine("Not true");
}
else if (value == WorkingDays.Thursday)
{
Console.WriteLine("True");
}
Console.ReadKey();
}
}
}
Output
True