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

来源:互联网 发布:原油模拟软件 编辑:程序博客网 时间:2024/05/01 06:07

枚举类型转换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)));

}