public enum color {red=1,green=2,blue=3}

Type typ = typeof(color);

 

1、根据 索引获取 字符串  结果为 “red”  字符串

string s = typ.GetEnumName(1);  

 

2、根据字符串获取索引 结果为 0
string s = Enum.Format(typ, Enum.Parse(typ, "Red"), "d");  

 

3、将枚举字符串如  1、的"red" 转换为  枚举类型

int type=1

color=(color)Enum.Parse(typeof(color), typeof(color).GetEnumName(type));

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
猜你喜欢
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-05
  • 2022-12-23
  • 2021-11-05
相关资源
相似解决方案