Hi,
When you pass the value (2nd) argument to Enum.Parse it will see if it can
match or convert the value that is passed. If the value is a empty string,
only has white space, or is a string but not one of the named constants
defined in the enumeration it will throw an ArgumentException. If it can
convert the value to the Enum’s underlying type it will create a new instance
of the enumeration with that value. For instance:
//with this enum
public enum Color { Red, Green, Blue }
//creates a new instance of Color with the value of 1 (Green)
Color c = (Color)Enum.Parse(typeof(Color), "1");
Console.WriteLine(c.ToString("G"));
//create a new instance of Color with the value of 3 (no name)
Color d = (Color)Enum.Parse(typeof(Color), "3");
Console.WriteLine(d.ToString("G"));
//create a new instance of Color with the value of 2 (Blue)
Color e = (Color)Enum.Parse(typeof(Color), "Blue");
Console.WriteLine(e.ToString("G"));
//Throw an ArgumentException because there is no match for the value
//and it cannot convert the value to the underlying type
Color f = (Color)Enum.Parse(typeof(Color), "Yellow");
Console.WriteLine(f.ToString("G"));
From the documentation I believe that this method has not changed from 1.1
to 2.0. If anyone knows any different please reply to this post.
I hope this helps
-----------------------