0

Here is my code for Enum:

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

Now I want same output as 3 but instead of providing Tempurature.Medium, I want to send Medium in variable value.
How can i do this?
Is this possible or not?

Anki
  • 65
  • 2
  • 11
  • Possible duplicate of [Casting string to enum](http://stackoverflow.com/questions/13970257/casting-string-to-enum) – mridula May 11 '17 at 13:16

2 Answers2

0

You can parse the string into the enum type Temperature:

Tempurature temperature = (Tempurature)System.Enum.Parse(typeof(Tempurature), "Medium", true);
Console.WriteLine("Temperature value is.." + (int)temperature);
mridula
  • 3,203
  • 3
  • 32
  • 55
0

Just use value

Console.WriteLine("Temperature value is.." + value);
VDWWD
  • 35,079
  • 22
  • 62
  • 79