Create an Enum in C#

How Enum is useful to us

Note:- > Enum is a Value type.
           >Enum keyword is use to declare an Enumeration.
           >Enum type can be (int, float,double byte and etc).
           > There must be numeric type for each Enum type.
           >Here first value of Enum type is 0.

       

for ex:-

1> Create a program to test the Enum.

Enum  day
{
      Sun,
      Mon,
      Tue,
      Wed,
      Thu,
      Fri,
      Sat
}


2> Place the Enum inside the Days Class.


 public  class Days
    {
        enum day
        {

            Sun,
            Mon,
            Tue,
            Wed,
            Thu,
            Fri,
            Sat,
        }

        public static void Main(string[] args)
        {
         
            string a = Console.ReadLine();
            int x = (int)day.Mon;
            Console.WriteLine("Mon = {0}",x);
        }

    }

Output:   Mon = 2


Share this

Previous
Next Post »