Enum with Switch Statement

We use enum keyword for declaring enumeration with enumeration list –set of named constants, here is code sample that shows how to use enumeration with Switch statement:

public enum Month

        {

            Jan,

            Feb,

            Mar,

            Apr,

            May,

            Jun,

        }

class Enum_With_Switch

{

      static void Main()

      {

            Month temp_Month = Month.Jan;

            switch (temp_Month)

            {

                case Month.Jan:

                    Console.WriteLine("this is January");

                    break;

                case Month.Feb:

                    Console.WriteLine("this is Febuary");

                    break;

                case Month.Mar:

                    Console.WriteLine("this is March");

                    break;

                case Month.Apr:

                    Console.WriteLine("this is April");

                    break;

                case Month.May:

                    Console.WriteLine("this is May");

                    break;

                case Month.Jun:

                     Console.WriteLine("this is June");

                    break;

            }

      }

}

Ebook Download
View all
FileInfo in C#
Read by 9.7k people
Download Now!
Learn
View all