• Enum枚举2


      //1.MyEnum:     

            textBox2.Text = "MyEnumTest:";  

    //>>>1.获得枚举类型的文字描述:          

    textBox2.Text += Environment.NewLine + EnumDescription.GetEnumText(typeof(MyEnum));

     //>>>2.获得某个枚举值的文字描述:    

             textBox2.Text += Environment.NewLine + EnumDescription.GetFieldText(MyEnum.I);

    //>>>3.获得枚举中各个字段的定义数组: 

             var filedTexts = EnumDescription.GetFieldTexts(typeof(MyEnum));//3.      

           string result = string.Empty;       

          foreach (EnumDescription val in filedTexts)             {

                    result += Environment.NewLine + string.Format("MyEnum的成员:{0} 数字值:{1} 描述文本:{2}", val.FieldName, val.EnumValue, val.EnumDisplayText);             }        

         textBox2.Text += result;

    //>>>4.绑定到下拉框:

     comboBox2.DisplayMember = "EnumDisplayText";
                comboBox2.ValueMember = "EnumValue";
                //comboBox2.DataSource = EnumDescription.GetFieldTexts(
                //    typeof(MyEnum),
                //    EnumDescription.SortType.Rank);
                comboBox2.DataSource = EnumDescription.GetFieldTexts(typeof(MyEnum),EnumDescription.SortType.DisplayText);

     [EnumDescription("人称")]    

    enum MyEnum     {

            [EnumDescription("你", 1)]   

          You = 1,

            [EnumDescription("我", 2)]  

           I = 2,     

        [EnumDescription("他", 3)]   

          He = 4,   

          [EnumDescription("她", 4)]

            She = 8

        }

        [EnumDescription("工作进度")]   

      enum WorkState     {        

    [EnumDescription("计划制定中")]         Planing,        

    [EnumDescription("一切就绪")]         Ready,      

       [EnumDescription("工作进行中")]         Processing,      

       [EnumDescription("完成工作")]         Finished     }

  • 相关阅读:
    zookeeperclient代码解读
    封装scrollView 循环滚动,tableViewCell(连载) mvc
    PHP经典项目案例-(一)博客管理系统5
    Android插件化(三)载入插件apk中的Resource资源
    比树莓派配置好接地气的香蕉派上手初体验
    HDU Group
    JVM 类的卸载
    JVM 自定义类加载器
    JVM 初始化阶段例子
    JVM 初始化阶段例子 final常量
  • 原文地址:https://www.cnblogs.com/xiaowei-blog/p/4186592.html
Copyright © 2020-2023  润新知