Simple Enum Example in C#

vishalneeraj-24503
Posted by vishalneeraj-24503 under C# category on | Points: 40 | Views : 493
Suppose,we have a Weekdays enum as follows:-
enum WeekDays
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}


Or we can also write Enum as:-
enum WeekDays
{
Sunday = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6
}


So,here,
Sunday is 0,
Monday is 1,
Tuesday is 2,
Wednesday is 3,
Thursday is 4,
Friday is 5 and,
Saturday is 6


Then accessing Enum values as:-
MessageBox.Show(WeekDays.Sunday);
MessageBox.Show(WeekDays.Monday); and so on.


Output:-
Sunday
Monday

Comments or Responses

Login to post response