zoukankan      html  css  js  c++  java
  • 枚举常用知识总结

    namespace EnumDemo
    {
        class Program
        {
            static void Main(string[] args)
            {
                var name = enumValue.first.ToString();
                Console.WriteLine($"输出第一个描述值:{ name }");
    
                var index = (int)enumValue.three;
                Console.WriteLine($"输出第三个索引值:{ index }");
    
    
                var description = typeof(enumValue).GetMember("two");
                var descriptionValue = description[0].GetCustomAttribute<DescriptionAttribute>().Description;
                Console.WriteLine($"输出第二个枚举的描述值:{ descriptionValue }");
    
    
                Console.WriteLine("输入枚举值判断是否存在当前枚举类型中:");
                var input=Console.ReadLine();
                var flag=Enum.IsDefined(typeof(enumValue), input);
                var output = "";
                switch (flag)
                {
                    case true:
                        output = "该值存在当前枚举中";
                        break;
                    case false:
                        output = "该值不存在当前枚举";
                        break;
                }
                Console.WriteLine(output);
                Console.Read();
    
            }
        }
    
        public enum enumValue
        {
            [Description("第一个")]
            first=1,
    
            [DescriptionAttribute("第二个")]
            two=2,
    
            [Description("第三个")]
            three=4
        }
    }

    掌握的知识如下:

      1、获取枚举枚举值

      2、获取枚举索引值

      3、获取枚举描述值

      4、判断字符串是否存在指定枚举中

  • 相关阅读:
    html5 自定义属性data-*
    企业微信接口授权
    js对象---字符串
    谈谈html5新增的元素及其他功能
    模拟缓存
    jdbc数据库连接
    面向对象的理解
    最简单的Spring+SpringMVC+Mybatis的整合
    EF报错 附加类型model失败
    c# Web服务远程“调用”调试
  • 原文地址:https://www.cnblogs.com/ZM191018/p/13234335.html
Copyright © 2011-2022 走看看