protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = GetEnunCallFunction(5); //根据枚举的int值取出string值
Label2.Text = GetEnunCallFunction2("Jeson").ToString();//根据枚举的string值取出int值
}
public enum EnunCallFunction
{
Tom = 0,
Tim = 1,
Jerry = 2,
Jack = 3,
Marry = 4,
Eva = 5,
Ada = 6,
Kiki = 7,
Jeson = 8,
Nick = 9,
Done = 10
}
//根据枚举的int值取出string值
protected string GetEnunCallFunction(int i)
{
EnunCallFunction call = (EnunCallFunction)Enum.Parse(typeof(EnunCallFunction), i.ToString());
return call.ToString();
}
//根据枚举的string值取出int值
protected int GetEnunCallFunction2(string str)
{
int i = (int)Enum.Parse(typeof(EnunCallFunction), str.ToString());
return i;
}
枚举取值(根据枚举的int值取出string值|根据枚举的string值取出int值)
最新推荐文章于 2024-07-30 16:45:01 发布