怎样将int或者String类型转换为枚举
展开全部
Enum.GetName(typeof(Days),4)
(Days)Enum.Parse(typeof(Days),4.ToString());
以下是msdn例子
enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
public static void Main()
{
Console.WriteLine("The entries of the Colors Enum are:");
foreach(string s in Enum.GetNames(typeof(Colors)))
Console.WriteLine(s);
Console.WriteLine();
Colors myOrange = (Colors)Enum.Parse(typeof(Colors), "4");
Console.WriteLine("The myOrange value has the combined entries of {0}", myOrange);
}
(Days)Enum.Parse(typeof(Days),4.ToString());
以下是msdn例子
enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
public static void Main()
{
Console.WriteLine("The entries of the Colors Enum are:");
foreach(string s in Enum.GetNames(typeof(Colors)))
Console.WriteLine(s);
Console.WriteLine();
Colors myOrange = (Colors)Enum.Parse(typeof(Colors), "4");
Console.WriteLine("The myOrange value has the combined entries of {0}", myOrange);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询