string to enum

How do you convert a string into an enumeration?

object Enum.Parse(System.Type enumType, string value, bool ignoreCase);

example:

enum Colour

{

Red,

Green,

Blue

}

Colour c = (Colour) Enum.Parse(typeof(Colour), "Red", true);

Console.WriteLine("Colour Value: {0}", c.ToString());

 

source: http://blogs.msdn.com/tims/archive/2004/04/02/106310.aspx

Published Thursday, April 24, 2008 11:05 AM by funky_rus

Comments

# re: string to enum

Thursday, April 24, 2008 4:24 PM by Wim Hollebrandse

Dude - why regurgitate stuff that was posted back in 2004? Besides, it's hardly anything worth posting.