码迷,mamicode.com
首页 > 其他好文 > 详细

枚举转集合

时间:2018-06-13 14:46:32      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:help   add   cat   声明   enum   values   IV   term   static   

声明类

//声明类
   public class EnumList
  {
      public int EnumValue { get; set; }
      public object EnumName { get; set; }
  }

创建WebHelper类添加方法

 /// <summary>
  /// 将枚举以list集合返回
  /// </summary>
  /// <param name="enumType"></param>
  /// <returns></returns>
  public static List<EnumList> EnumToList(Type enumType)
  {
      List<EnumList> Emlist = new List<EnumList>();
      foreach (int i in Enum.GetValues(enumType))
      {
      EnumList em = new EnumList();
      em.EnumValue = i;
      em.EnumName = Enum.GetName(enumType, i);
      Emlist.Add(em);
      }
      return Emlist;
  }

枚举

 public enum WatermarkLocation
    {
        中间 = 0,
        左上 = 1,
        右上 = 2,
        左下 = 3,
        右下 = 4,
        中上 = 5,
        中下 = 6
    }

调用

WebHelper.EnumToList(typeof(WatermarkLocation))

 

枚举转集合

标签:help   add   cat   声明   enum   values   IV   term   static   

原文地址:https://www.cnblogs.com/xiaonangua/p/9176661.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!