我是靠谱客的博主 魁梧樱桃,这篇文章主要介绍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对象,你可以替换成你的下拉框对象。

最后

以上就是魁梧樱桃最近收集整理的关于c# EnumHelper枚举常用操作类的全部内容,更多相关c#内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(259)

评论列表共有 0 条评论

立即
投稿
返回
顶部