如何返回与给定字符串匹配的枚举值?

Ran*_*ten 2 c# enums

所以我有一个字符串,我希望从枚举中获取一个值,并返回与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)