手机
当前位置:查字典教程网 >编程开发 >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中Panel实现用鼠标操作滚动条的实例方法

C#的WebBrowser的操作与注意事项介绍

C#中timer类的用法总结

c#各种Timer类的区别与用法介绍

C# 中的??操作符浅谈

C# String Replace高效的实例方法

C#枚举数值与名称的转换实例分享

c# Base关键字的使用

C# Winform 调用系统接口操作 INI 配置文件的代码

Winform跨线程操作的简单方法

精品推荐
分类导航