Possible Duplicate:
How do I Convert a string to an enum in C#?




我有一个int类型的枚举:

public enum BlahType
{
       blah1 = 1,
       blah2 = 2
}


如果我有一个字符串:

string something = "blah1"


如何将其转换为BlahType?

最佳答案

您要Enum.Parse

BlahType blahValue = (BlahType) Enum.Parse(typeof(BlahType), something);

07-28 09:55