博客园站长
这是人类成长进步中记录的每一时刻

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));

posted on 2012-10-27 12:58  dm3344  阅读(1771)  评论(0编辑  收藏  举报