zoukankan      html  css  js  c++  java
  • C# Enum转换

    public class Enum2
        {
            
            public Dictionary<string, int> GetEnumItems<T>()
            {
                Dictionary<string, int> dicResult = new Dictionary<string, int>();
                T obj = default(T);
                Type type = obj.GetType();
                foreach (string s in type.GetEnumNames())
                {
                    dicResult.Add(s, Convert.ToInt16((T)Enum.Parse(typeof(T), s, true)));
                }
                return dicResult;
            }
    
            public T GetEnumByEnumName<T>(string enumName)
            {
                T result = default(T);
                if (Enum.IsDefined(typeof(T), enumName))
                {
                    result = (T)Enum.Parse(typeof(T), enumName, true);
                }
                else
                {
    
                }
                return result;
            }
    
            public T GetEnumByEnumIndex<T>(int ienum)
            {
                T result = default(T);
                if (Enum.IsDefined(typeof(T), ienum))
                {
                    result = (T)Enum.Parse(typeof(T), ienum.ToString(), true);
                }
                else
                {
    
                }
                return result;
            }
    一个人成就的大小与承担责任的多少是成正比
  • 相关阅读:
    HDU 1058
    Codeforces 349C
    HDU 2602
    HDU 2571
    HDU 2955
    HDU 2084
    HDU 1003
    HDU 1506 & 1505
    POJ 1854
    HDU 2095
  • 原文地址:https://www.cnblogs.com/qxoffice2008/p/3926937.html
Copyright © 2011-2022 走看看