手机
当前位置:查字典教程网 >编程开发 >C#教程 >c# EnumHelper枚举常用操作类
c# EnumHelper枚举常用操作类
摘要:测试代码如下:namespaceCutPictureTest.Comm{publicclassEnumHelper{publicstatic...

测试代码如下:

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# Winform 调用系统接口操作 INI 配置文件的代码

C# ConfigHelper 辅助类介绍

c# list部分操作实现代码

async and await 的入门基础操作

Winform跨线程操作的简单方法

C# 遍历枚举类型的所有元素

c# Base关键字的使用

简介Winform中创建用户控件

c# 引用类型和值类型

C# 中的??操作符浅谈

精品推荐
分类导航