C sharp - C# Enums Explained

What is an Enum?

An enum (short for enumeration) is a value type in C# that allows you to define a set of named constants. It makes your code more readable, type-safe, and easy to maintain when dealing with a fixed set of related values.

Syntax of Enum

enum EnumName
{
    Constant1,
    Constant2,
    Constant3
}

Example: Days of the Week

enum Day
{
    Sunday,
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday
}

You can then use it like this:

Day today = Day.Monday;
Console.WriteLine("Today is: " + today);