Software Developer's Resources

Shopping Cart Systems
Mobile Text Marketing Solutions
Online Backup Solutions
ASP.NET Web Development
Skip Navigation Links.

How to Convert Index or Integer to Enum Name

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;
}