Thursday, 13 December 2012

Convert an Enum to String C#

Convert an Enum to String C#


enum colors{red,blue,green};

private void Convert_Enum_To_String()
{
         foreach(String strColor in Enum.GetNames(typeof(colors)))
         {
             Console.WriteLine(strColor);
         }
}

Enum value type has Static method GetNames, Which will convert all enum constants to strings.