输出枚举的中文名称
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Net.Sockets; using System.IO; using System.ComponentModel; using System.Runtime.Serialization; using System.Reflection; using System.Diagnostics; using System.Collections.Specialized; namespace DomainWhois { class Program { static void Main(string[] args) { Type type = typeof(DescriptionAttribute); foreach (FieldInfo fi in typeof(CustomerRankType).GetFields()) { object[] arr = fi.GetCustomAttributes(type, true); if (arr.Length > 0) { Console.WriteLine(((DescriptionAttribute)arr[0]).Description); } }Console.ReadLine(); } } /// <summary> /// 用户等级枚举 /// </summary> [Serializable] public enum CustomerRankType { [Description("游客")] Unknown = 0, [Description("初级会员")] JuniorMember = 1, [Description("青铜会员")] BronzeMember = 2, [Description("白银会员")] SilverMember = 3, [Description("黄金会员")] GoldMember = 4, [Description("钻石会员")] DiamondMember = 5, [Description("皇冠会员")] CrownMember = 6, [Description("至尊会员")] EggEmperor = 7 } }
作者:Bober Song
出处:http://bober.cnblogs.com/
CARE健康网: http://www.aicareyou.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://bober.cnblogs.com/
CARE健康网: http://www.aicareyou.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。