How to get int value of Enum by providing string value in varibale
这是我的枚举代码:
1 2 3 4 5 6 7 8 9 10 11 12 | enum Tempurature { Low = 2, Medium, High, }; Temperature value = Tempurature.Medium; int val = (int)value; Console.WriteLine("Temperature value is.." + val); Output is : Temperature value is.. 3 |
现在我想要和3一样的输出,但不是提供温度。介质,我想发送变量值的介质。我该怎么做?是否可能?
只需使用EDOCX1[1]
1 | Console.WriteLine("Temperature value is.." + value); |
可以将字符串解析为枚举类型
1 2 | Tempurature temperature = (Tempurature)System.Enum.Parse(typeof(Tempurature),"Medium", true); Console.WriteLine("Temperature value is.." + (int)temperature); |