string to enum 字符串转枚举

string serverAction="设置";

ServerAction sAction = (ServerAction)Enum.Parse(typeof(ServerAction), serverAction);
if (Enum.IsDefined(typeof(ServerAction), sAction))
{
//ok
}

原文地址:https://www.cnblogs.com/94cool/p/2812548.html