c# EnumHelper枚举常用操作类
2016-11-30 22:52
585 查看
测试代码如下:
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对象,你可以替换成你的下拉框对象。
相关文章推荐
- EnumHelper枚举常用操作类
- C#枚举的不常用方法Enum.Parse&Enum.GetNames
- 在C#编程中玩转枚举,分享我的EnumHelper。
- C#Enum常用枚举操作
- C#枚举的不常用方法Enum.Parse&Enum.GetNames
- 关于C#的enum枚举
- C# 枚举类型转换字符串 Enum to string,枚举转换为下拉菜单 Enum DropDownList
- enum : C#中的枚举类型,原来有这么多用法
- C#的Enum——枚举 (转)
- Enums and Structs in C#(C#里的枚举和结构) (from codeproject)
- 关于C#的enum枚举
- C#的Enum——枚举
- C# String 类型 转为 Enum 枚举类型
- C#编程:枚举(enum)与结构(struct)的定义和使用方法
- c# 枚举 enum
- C#字符串操作类StringHelper源码
- c#服务器端枚举(enum)转为客户端javascript的枚举(json)
- C#枚举类型enum
- C# 枚举(enum)-设计
- C# 根据枚举名(string)获得enum中的枚举值