所以我有一个字符串,我希望从枚举中获取一个值,并返回与string相同的名称.例:
enum Types{ one, two, three } private Types getType(string value){ //Let's say value is "two" return Types.value; //This should return the enum "two" of Types }
我希望我说得够清楚!
使用Enum.Parse
var t = (Types)Enum.Parse(typeof(Types), "two");