Usage

Referencing

enum DaysOfWeek
{
    Monday,
    Tuesday, 
    Wednesday, 
    Thursday, 
    Friday, 
    Saturday, 
    Sunday
}

DaysOfWeek today = DaysOfWeek.Monday;

if(today == DaysOfWeek.Saturday || today == DaysOfWeek.Sunday)
{
    Console.WriteLine("Weekend");
}
else
{
    Console.WriteLine("Weekday");
}
  • Enums are particularly useful for passing parameters and ensuring the value is one of a set of predefined values.

Retrieving the integer value of an Enum

  • Below, the value of dayNumber will be 0 (if the enum declaration was the first of the three above).

Last updated