Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
In this blog, we will learn about Enums in C#. Enum(also called enumeration) in C# is a user-defined value type representing a list of named integer constants. It improves the program's readability maintainability and reduces complexity.
Syntax
enum_name is the name that we want to give to our enum list. We use comma (,) to separate the items in our enum list.
enum enum_name {
enumeration list
};
Example
enum months
{
// items of the enum
January,
February,
March,
April,
May,
June,
July
}
If we do not give values to the enum items, the items are provided an integer value by the compiler by default. The compiler will assign values starting from 0, and it increments the value by one each time we add an item to our enum.
enum months
{
// items of the enum
January, //0
February, //1
March, //2
April, //3
May, //4
June //5
July //6
}
Assigning our values
We can change the values given to the enum item. If we change the value assigned to one of our given months, e.g. March is set to 10. Then the compiler will assign value sequentially to the other months, i.e., it will increment by one from 10:
enum months
{
// items of the enum
January, //0
February, //1
March=10, //10
April, //11
May, //12
June, //13
July //14
}
Access an Enum
We can access an enum item using the dot syntax:
Example
using System;
namespace Example {
enum months
{
// items of the enum
January,
February,
March,
April,
May,
June,
July
}
public class Program {
public static void Main(string[] args)
{
Console.WriteLine( months.January);
Console.WriteLine( months.February);
Console.WriteLine( months.March);
Console.WriteLine( months.April);
Console.WriteLine(months.May);
Console.WriteLine( months.June);
Console.WriteLine( months.July);
}
}
}
Output
January,
February
March
April
May
June
July
Get integer values from enum
We have to explicitly convert an item in the enum list to get the integer value associated with that item.
Example
In this example, we will see how to convert the items to an integral value.
using System;
namespace Example {
enum months
{
// items of the enum
January,
February,
March,
April,
May,
June,
July
}
public class Program{
public static void Main(string[] args)
{
// Prints the integer values of the items
Console.WriteLine("The value of January in months " + "enum is " + (int)months.January);
Console.WriteLine("The value of February in months " + "enum is " + (int)months.February);
Console.WriteLine("The value of March in months" + "enum is " + (int)months.March);
Console.WriteLine("The value of April in months " + "enum is " + (int)months.April);
Console.WriteLine("The value of May in months " + "enum is " + (int)months.May);
Console.WriteLine("The value of June in months " + "enum is " + (int)months.June);
Console.WriteLine("The value of June in months " + "enum is " + (int)months.July);
}
}
}
Output
The value of January in months enum is 0
The value of February in months enum is 1
The value of March in months enum is 2
The value of April in months enum is 3
The value of May in months enum is 4
The value of June in months enum is 5
The value of July in months enum is 6
Let's look at enum rules to understand enums properly.
Enum Rules
We can assign one integer value to two enum items in an enum.
The compiler gives integer values to the enum items if we do not assign them. The first item is set to 0, and the compiler increments by one for other items in the enum list.
We can only assign integer values to the enum items. We can not assign strings as values.
Now, let's move to the FAQs section to clear our doubts regarding enums.
FAQs
Why are enums used in C#? In C#, an enum (or enumeration type) assigns constant names to a group of numeric integer values. It makes constant values more readable, for example, WeekDays. Monday is more readable than number 0 when referring to the day in a week.
Where should enums be defined C#? Enums are defined inside a namespace, class, or structure. It is declared using the enum keyword followed by the name of our enum.
Can enum have methods C#? C# Does not allow the use of methods in enumerators as it is not a class-based principle but rather a two-dimensional array with a string and value.
Is the enum value type in C#? C# enum is a value type with a set of related constants often referred to as an enumerator list. The C# enum keyword is used to declare an enumeration. It is a primitive data type that is user-defined.
Can enums be NULL in C#? An enum is a "value" type in C# (means the enum is stored as whatever value it is, not as a reference to a place in memory where the value itself is stored). We can not set value types to null (since null is used for reference types only).
In this article, we extensively discussed enums in C#. We have seen the syntax of enums and how to use enums in our C # program. We have also seen different values an enum can take. In the end, we discussed the rule of enums.
We hope that this blog has helped you enhance your knowledge regarding enums in C# and if you want to learn more, check out articles on Coding Ninjas Studio. Do upvote our blogs to help other ninjas grow.
Happy Coding!
Live masterclass
Zomato Data Analysis Case Study: Ace 25L+ Roles in FoodTech
by Abhishek Soni
16 Mar, 2026
01:30 PM
Data Analysis for 20L+ CTC@Flipkart: End-Season Sales dataset
by Sumit Shukla
15 Mar, 2026
06:30 AM
Beginner to GenAI Engineer Roadmap for 30L+ CTC at Amazon
by Shantanu Shubham
15 Mar, 2026
08:30 AM
Multi-Agent AI Systems: Live Workshop for 25L+ CTC at Google
by Saurav Prateek
16 Mar, 2026
03:00 PM
Zomato Data Analysis Case Study: Ace 25L+ Roles in FoodTech
by Abhishek Soni
16 Mar, 2026
01:30 PM
Data Analysis for 20L+ CTC@Flipkart: End-Season Sales dataset