一: 在C#中将String转换成Enum:
object Enum.Parse(System.Type enumType, string value, bool ignoreCase);
所以,我们就可以在代码中这么写:
enum Colour
{
Red,
Green,
Blue
}
// ...
Colour c = (Colour) Enum.Parse(typeof(Colour), "Red", true);
Console.WriteLine("Colour Value: {0}", c.ToString());
// Picking an invalid colour throws an ArgumentException. To
// avoid this, call Enum.IsDefined() first, as follows:
string nonColour = "Polkadot";
if (Enum.IsDefined(typeof(Colour), nonColour))
c = (Colour) Enum.Parse(typeof(Colour), nonColour, true);
else
MessageBox.Show("Uh oh!");
二: 在C#中将转Enum换成String:
原文:http://www.cnblogs.com/xdot/p/5239517.html