Introduction: Enum in C#.Net

In this post, we will learn about Enum in C#.Net with an example.An enumeration is a set of named integer constants along with some value. It is declared using the enum keyword.

C# enumerations are value data type. i.e. enumeration contains its own values and cannot inherit or cannot pass inheritance.

The default underlying type of the enumeration member is int. By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1.


In my previous posts I have explained various topics like Collections in C#SortedSet in C#.Net,Stack in C#,Queue in C#.Net,LinkedList in C#.Net. Now in this post, I will explain about Enum in C#.Net with appropriate example.

Now, Create Console Application in Visual Studio and write below line of code.

using System;
using System.Collections;

namespace ConsoleDemo
    class Program
        public enum WeekDays
            Sunday = 1, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday

        static void Main(string[] args)
            Console.WriteLine("Day of week {0} {1}", (int)WeekDays.Sunday, WeekDays.Sunday);
            Console.WriteLine("Day of week {0} {1}", (int)WeekDays.Monday, WeekDays.Monday);
            Console.WriteLine("Day of week {0} {1}", (int)WeekDays.Tuesday, WeekDays.Tuesday);
            Console.WriteLine("Day of week {0} {1}", (int)WeekDays.Wednesday, WeekDays.Wednesday);
            Console.WriteLine("Day of week {0} {1}", (int)WeekDays.Thursday, WeekDays.Thursday);
            Console.WriteLine("Day of week {0} {1}", (int)WeekDays.Friday, WeekDays.Friday);
            Console.WriteLine("Day of week {0} {1}", (int)WeekDays.Saturday, WeekDays.Saturday);
Enum in C#.Net

Enum in C#.Net

I hope you got an idea about Enum in C#.Net .
I would like to have feedback from my blog readers.
Your valuable feedback, question, or comments about this article are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *