代码改变世界

C# 枚举类型转换字符串 Enum to string,枚举转换为下拉菜单 Enum DropDownList

2011-01-14 16:36  小sa  阅读(915)  评论(0编辑  收藏  举报

枚举类型转换Tips

  EnumType 

  {

    a=1,

    b=2,

    c=3

  }

 

EnumType newtype=(EnumType)Enum.Parse(typeof(EnumType),"a");

 

string[] names=Emum.GetNames(typeof(EnumType));

Array values=Enum.GetValues(typeof(EnumType));

for(int i=0;i<values.length-1;i++)

{

  DropDownList.Items.Add(new ListItem(names[i],values.GetValue(i)));

}