枚举转化(小技巧)

public enum E
{
All=10,
Up=20,
Down=30
}

string ID =E.All.ToString()//枚举转字符串

int ID = Convert.ToInt32(E.All);//枚举转整型

 

E ID = (E)10//整型转枚举

E ID = (E)System.Enum.Parse(typeof(E), "All", true);//字符串转枚举

详细看下面链接

http://www.cnblogs.com/cuihongyu3503319/archive/2009/02/04/1383987.html

 

你可能感兴趣的:(小技巧)