28 January 2010

How to enumerate enum values?

To enumerate an enum use the GetValues of the Enum class.

For example:

foreach (int carColorValue in Enum.GetValues(typeof(CarColorEnum))
{
string carColorName = Enum.GetName(typeof(CarColorEnum), carColorValue);
}

No comments: