通过本文主要向大家介绍了c#枚举类,c#定义枚举,c#枚举,c#中枚举,c#遍历枚举等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
测试代码如下:
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;
}
}
}
</div>
调用方式:
System.Collections.Hashtable arr = Comm.EnumHelper.EnumToHashtable(typeof(tImageFormat));
foreach (string item in arr.Values)
cb.Items.Add(item);
</div>
其中的cb表示ComboBox对象,你可以替换成你的下拉框对象。
</div>
