Enum.Parse()具体如何使用?
namespace Enum_Parse_
{
class Program
{
[FlagsAttribute]//指示可以将枚举作为位域(即一组标志)处理
enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
static void Main(string[] args)
{
Console.WriteLine("The entries of the Colors Enum are:");
foreach (string colorName in Enum.GetNames(typeof(Colors)))
{
Console.WriteLine("{0}={1}", colorName,
Convert.ToInt32(Enum.Parse(typeof(Colors), colorName)));
}
Console.WriteLine();
Colors myOrange = (Colors)Enum.Parse(typeof(Colors), "Red, Yellow");
Console.WriteLine("The myOrange value {1} has the combined entries of {0}",
myOrange, Convert.ToInt64(myOrange));
}
/*
This code example produces the following results:
The entries of the Colors Enum are:
Red=1
Green=2
Blue=4
Yellow=8
The myOrange value 9 has the combined entries of Red, Yellow
*/
}
}
浙公网安备 33010602011771号