[C#] Getting the value of an enum through a string

Heitor Helmer Herzog
1 min readOct 28, 2017

--

enum Pets
{
Dog= 1,
Cat = 2
}

// Passing the description you want the value
string description= "dog";
// The value will be 1 as expected.
int value = (int)Enum.Parse(typeof(Pets), description);

--

--

Heitor Helmer Herzog
Heitor Helmer Herzog

Written by Heitor Helmer Herzog

Software developer, In love with games and the industry. Let’s code! About me: www.linkedin.com/in/heitorhherzog

No responses yet