Enum

Enum or Enumeration is a special class that contains collection of constant values. Just because all the value stored inside Enum is constant we cannot change its value and every value will be a read-only one. Enum type is a special data type that enables for a variable to be a set of predefined constants. We'll discuss all about these with code examples

CODE

EG 1 . Creating an Enum called Weekdays.

enum weekdays {
    Monday, Tuesday, Wednesday, Thursday, Friday
}

class Program {
    static void main(){
        weekdays today = weekdays.Wednesday;
        if (today == weekdays.Monday) {
            Console.WriteLine("Do Monday Works");
        }
        else if (today == weekdays.Tuesday) {
            Console.WriteLine("Do Tuesday Works");
        }
        else if (today == weekdays.Wednesday) {
            Console.WriteLine("Do Wednesday Works");
        }
        else if (today == weekdays.Thursday) {
            Console.WriteLine("Do Thursday Works");
        }
        else if (today == weekdays.Friday) {
            Console.WriteLine("Do Friday Works");
        }
    }
}



EG 2 . Creating an Enum called Seasons.

enum Seasons {
    Winter, Spring, Summer, Fall
}

class Program {
    static void main(){
        Seasons thisMonth = Seasons.Summer;
        if (thisMonth == Seasons.Winter) {
            Console.WriteLine("The Average temperature is 27°C");
        }
        else if (thisMonth == Seasons.Spring) {
            Console.WriteLine("The Average temperature is 30°C");
        }
        else if (thisMonth == Seasons.Summer) {
            Console.WriteLine("The Average temperature is 34°C");
        }
        else if (thisMonth == Seasons.Fall) {
            Console.WriteLine("The Average temperature is 32°C");
        }
    }
}



(Click Here, For more exercises)