c# EnumHelper c# EnumHelper枚举常用操作类

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

c# EnumHelper c# EnumHelper枚举常用操作类

  2021-03-22 我要评论
想了解c# EnumHelper枚举常用操作类的相关内容吗,在本文为您仔细讲解c# EnumHelper的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:c#,EnumHelper,下面大家一起来学习吧。

测试代码如下:

namespace CutPictureTest.Comm
{

  public class EnumHelper
  {

    public static System.Collections.ArrayList GetName(Type enumType)
    {
      System.Collections.ArrayList arr = new System.Collections.ArrayList();
      string[] n = System.Enum.GetNames(enumType);
      foreach (string item in n)
        arr.Add(item);
      return arr;

    }

    public static T ToEnum<T>(string strEnum)
    {
      T t = (T)Enum.Parse(typeof(T), strEnum);
      return t;
    }

    public static System.Collections.Hashtable EnumToHashtable(Type enumType)
    {
      System.Collections.Hashtable ht = new System.Collections.Hashtable();
      Array arr = System.Enum.GetValues(enumType);
      for (int i = 0; i < arr.Length; i++)
        ht.Add(Convert.ToInt16(arr.GetValue(i)), arr.GetValue(i).ToString());
      return ht;
    }
  }
}

调用方式:

System.Collections.Hashtable arr = Comm.EnumHelper.EnumToHashtable(typeof(tImageFormat));
      foreach (string item in arr.Values)
        cb.Items.Add(item);

其中的cb表示ComboBox对象,你可以替换成你的下拉框对象。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们