所以我有一个字符串,我想从枚举中获取一个值以返回与字符串同名的值。示例:
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");
关于c# - 如何返回与给定字符串匹配的枚举值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16800946/