所以我有一个字符串,我希望从枚举中获取一个值,并返回与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
}
Run Code Online (Sandbox Code Playgroud)
我希望我说得够清楚!
I4V*_*I4V 10
使用Enum.Parse
var t = (Types)Enum.Parse(typeof(Types), "two");
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
132 次 |
最近记录: |