High-Performance Development - C#, VB, SQL, ASP.NET

Slogan Text

This article describes how to get the name of an enum associated with an integer or index.

Suppose we want to get a list of all the names of the days of the week from the enum DayOfWeek. How do we accomplish this?

We'll use the Enum.GetName method to get the name associated with an integer value.

public string DaysOfWeekList()
{
    string Delimiter = "";
    string Names = "";

    for( Day = 0; Day < 7; Day++)
    {
        Names += Delimiter + Enum.GetName(typeof(DayOfWeek), Day);
        Delimiter = ",";
    }

    return Names;
}