在C#当字符串和枚举类型的转换是很常见的功能。特此记录一下:
using System;
public enum Flowers
{
None,
Daisy= 1,
Lili = 2,
Rose = 3
}
class Conversion{
static void Main()
{
string stringvalue = "Rose";
Flowers Flower = (Flowers)Enum.Parse(typeof(Flowers), stringvalue);
//To check if we have converted successfully
if(Flower == Flowers.Rose)
{
Console.WriteLine("The Flower is Rose");
}
}
}