int获取枚举
/// <summary> /// int获取枚举 /// </summary> /// <typeparam name="T">枚举集合</typeparam> /// <param name="num"></param> /// <returns></returns> public static T NumToEnum<T>(int num) { foreach (var myCode in Enum.GetValues(typeof(T))) { if ((int)myCode == num) { return (T)myCode; } } throw new ArgumentException(string.Format("{0} 未能找到对应的枚举.", num), "Description"); }
例子
int cardtype = Common.ObjectToInt(_context.Request["cardtype"]); CardVolume.CardTypeEnum cardtypeenum = Common.NumToEnum<CardVolume.CardTypeEnum>(cardtype);