How to Convert Integer or Index 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;
}


Site Map | Printable View | © 2008 - 2012 Sandy Pond Consulting | Powered by mojoPortal | HTML 5 | CSS | Design by styleshout