Tuesday, 13 March 2018

042 C# Enum

Enum
enum is an keyword to inform compiler that it is an enumeration. Enumeration consist a set of values  related name constant , it is called enumeration list.The value should be distinct. Enumeration is declared generally under a namespace, but it can be declared under structure and class also. It is a value type object and do not support inheritance. By default for the set of value , enumeration value start from zero  if not specified. Enumeration value can be integer, byte, float , double.Below is the
enumeration with default enumeration value.

Example 1

using System;
namespace student
{
               public class Student
                {
                        enum DayofWeek
                         {
                              Sunday, Monday, Tuesday, Wednesday, Thrusdad, Friday, Saturday
                          };
                          static void Main()
                          {
                             int i = (int)DayofWeek.Tuesday;
                             Console.WriteLine("Value of i is " + i.ToString());
                            Console.ReadKey();
                          }


}
Output :
Value of i is 2

Example 2
Below is the example with first enumeration value 12


using System;
namespace student
{
             public class Student
             {
                    enum DayofWeek
                    {
                             Sunday=12, Monday, Tuesday, Wednesday, Thrusdad, Friday, Saturday
                   };

               static void Main()
              {
               int i = (int)DayofWeek.Tuesday;
               Console.WriteLine("Value of i is " + i.ToString());
               Console.ReadKey();
             }
        }
}


No comments:

Post a Comment

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...