EnumHelper枚举常用操作类
2016-11-21 09:07
267 查看
在项目中需要把枚举填充到下拉框中,所以使用统一的方法实现,测试代码如下:
调用方式:
其中的cb表示ComboBox对象,你可以替换成你的下拉框对象。
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#编程中玩转枚举,分享我的EnumHelper。
- 枚举Enum 的常用方法
- net core 使用tagHelper将 enum枚举类型转换为下拉列表select
- 枚举(enum)的常用操作
- java 几种常用的枚举(Enum)方法
- C#Enum常用枚举操作
- C#枚举的不常用方法Enum.Parse&Enum.GetNames
- C#枚举的不常用方法Enum.Parse&Enum.GetNames
- 枚举(enum)的常用操作
- 枚举-enum常用事例
- java 枚举(Enum)常用使用总结
- 马士兵J2SE-第六章-常用类-String类、StringBuffer类、枚举ENUM
- Grails中利用枚举(enum)来实现Status、Type功能
- 关于enum的一些常用方法
- ENUM 枚举使用总结
- python入门笔记(Day7)--slots,@property,MixIn,定制(str,iter,getitem,getattr,call)枚举(Enum)元type,metaclass,ORM
- Java枚举enum以及应用:枚举实现单例模式
- linux常用命令---目录操作类
- 全面解读Java中的枚举类型enum的使用