当前位置: 移动技术网 > IT编程>开发语言>c# > c# EnumHelper枚举常用操作类

c# EnumHelper枚举常用操作类

2019年07月18日  | 移动技术网IT编程  | 我要评论
测试代码如下: namespace cutpicturetest.comm { public class 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对象,你可以替换成你的下拉框对象。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网