参考网址:https://www.cnblogs.com/SeNaiTes/p/9552348.html
/// <summary> /// 任务状态枚举 /// </summary> public enum NeedsinfoStatus { [Description("已取消")] 已取消 = 0, [Description("待发布")] 待发布 = 1, [Description("待审核")] 待审核 = 3, [Description("驳回")] 驳回 = 4, [Description("待签约")] 待签约 = 5, [Description("待确认")] 待确认 = 7, [Description("已确认/待评价")] 待评价 = 9, [Description("已完成")] 已完成 = 11, [Description("已支付 ")] 已支付 = 13, [Description("已评价 ")] 已评价 = 15, }
1、通过当前枚举值(int)获取枚举文字说明
item.Status=1;
item.StatusName = Enum.GetName(typeof(NeedsinfoStatus), item.Status).ToString();
item.StatusName ="待发布";
2、其他说明
var x = (Test)Enum.Parse(typeof(Test), "男");//男 var x2 = Enum.Parse(typeof(Test), "男");//男 var x3 = Enum.GetName(typeof(Test),0);//"男" foreach (var item in Enum.GetValues(typeof(Test))) { var v = item;//男[女] var v2 = (int)item;//0[1] var t = item.GetType();//{Name = "Test" FullName = "BaseControl.Enum.Test"} var g = item.ToString();//"男"["女"] }
C# typeof() 和 GetType()区是什么? 没搞明白