• 枚举的变换


    枚举用于选择下拉框

     1 /// <summary>
     2         /// 将枚举绑定到下拉框
     3         /// </summary>
     4         /// <typeparam name="T"></typeparam>
     5         /// <param name="p_Value">选中值</param>
     6         /// <param name="p_Tip">提示语</param>
     7         /// <param name="IsShowSelectTip">是否显示提示语</param>
     8         /// <param name="RemoveIndex">排除不显示的枚举值(索引)</param>
     9         /// <returns></returns>
    10         public static SelectList EnumToListItem<T>(int? p_Value, string p_Tip = "", bool IsShowSelectTip = true, int RemoveIndex = -10)
    11         {
    12             object _selectValue = null;
    13             if (p_Value.HasValue)
    14             {
    15                 _selectValue = p_Value.Value;
    16             }
    17             var item = new List<SelectListItem>();
    18             if (IsShowSelectTip)
    19             {
    20                 item.Add(new SelectListItem { Value = "", Text = "--请选择" + p_Tip + "--" });
    21             }
    22             foreach (int s in Enum.GetValues(typeof(T)))
    23             {
    24                 //item.Add(new SelectListItem() { Text = Enum.GetName(typeof(T), s), Value = s.ToString() });
    25                 if (RemoveIndex != s)
    26                 {
    27                     item.Add(new SelectListItem { Text = Enum.GetName(typeof(T), s), Value = s.ToString() });
    28                 }
    29             }
    30             var list = new SelectList(item, "Value", "Text", _selectValue);
    31             return list;
    32         }
    View Code

    将枚举转换为字典

     1 /// <summary>
     2         /// 将枚举转换成字典集合
     3         /// </summary>
     4         public static IDictionary<object, object> EnumToList<T>()
     5         {
     6             Dictionary<object, object> m_Dic = new Dictionary<object, object>();
     7             string m_Value = string.Empty;
     8             foreach (int s in Enum.GetValues(typeof(T)))
     9             {
    10                 m_Value = Enum.GetName(typeof(T), s);
    11                 m_Dic.Add(s, m_Value);
    12             }
    13             return m_Dic;
    14         }
    View Code
  • 相关阅读:
    AtCoder Beginner Contest 113 D Number of Amidakuji
    UVA
    mt19937 -- 高质量随机数
    牛客网NOIP赛前集训营-提高组(第七场)C 洞穴
    牛客OI周赛4-提高组 C 战争(war)
    牛客OI周赛4-提高组 B 最后的晚餐(dinner)
    bzoj 4318 || 洛谷P1654 OSU!
    Tourists Codeforces
    bzoj 1791 [Ioi2008]Island 岛屿
    洛谷 P2231 [HNOI2002]跳蚤
  • 原文地址:https://www.cnblogs.com/HuberyHu/p/5319253.html
Copyright © 2020-2023  润新知