【C#枚举】根据EnumName获取Value

 1         public static int GetEnumValue(Type enumType, string enumName)
 2         {
 3             try
 4             {
 5                 if (!enumType.IsEnum)
 6                     throw new ArgumentException("enumType必须是枚举类型");
 7                 var values = Enum.GetValues(enumType);
 8                 var ht = new Hashtable();
 9                 foreach(var val in values)
10                 {
11                     ht.Add(Enum.GetName(enumType, val), val);
12                 }
13                 return (int)ht[enumName];
14             }
15             catch (Exception e)
16             {
17                 throw e;
18             }
19         }
原文地址:https://www.cnblogs.com/tongyinaocan/p/5482101.html