zoukankan      html  css  js  c++  java
  • 【代码保留】枚举的键与值

    随手写的,同事突然迷惑于枚举类型

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication1
    {
        class Program
        {
            public enum EnumSample
            {
                nomeaningvalue = -1,
                value1 = 1,
                value2 = 21
            }

            static void Main(string[] args)
            {
                string key = "value2";

                List<int> values = new List<int>();
                values.Add(1);
                values.Add(21);

                EnumSample sample = GetEnum(key, values);

                if (sample != EnumSample.nomeaningvalue)
                {
                    Console.WriteLine(sample.GetHashCode());
                }
                else
                {
                    Console.WriteLine("Not exists the key = " + key);
                }
            }

            static EnumSample GetEnum(string compare,List<int> values)
            {
                EnumSample result = EnumSample.nomeaningvalue;
                foreach(int value in values)
                {
                    EnumSample sample = (EnumSample)value;
                    if (sample.ToString() == compare)
                    {
                        result = sample;
                        break;
                    }
                }
                return result;
            }
        }

        //21
        //请按任意键继续. . .
    }

  • 相关阅读:
    go语言学习之从例子开始
    分享一个不错的Unittest测试报告
    selenium各种定位方法(转)
    HTMLTESTRunner自动化测试报告增加截图功能
    selenium之chrome驱动版本
    Python基础(六) python生成xml测试报告
    vue+elementUI 表头按钮
    vue+elementUI滚动条
    vue表格表头添加按钮
    elementUI升级版本后Dialog弹空不显示问题
  • 原文地址:https://www.cnblogs.com/volnet/p/970622.html
Copyright © 2011-2022 走看看