C# convert string to enum

1
2
3
4
5
6
7
8
9
10
   enum Colour
   {
      Red,
      Green,
      Blue
   }

   // ...
   Colour c = (Colour) Enum.Parse(typeof(Colour), "Red", true);
   Console.WriteLine("Colour Value: {0}", c.ToString());

Taken from here:
http://blogs.msdn.com/b/tims/archive/2004/04/02/106310.aspx

Leave a Reply