Answers for "enum convert back string to number"

C#
1

casting string to enum type

string str = "Dog";
Animal animal = (Animal)Enum.Parse(typeof(Animal), str);  // Animal.Dog
Animal animal = (Animal)Enum.Parse(typeof(Animal), str, true); // case insensitive
Posted by: Guest on December-11-2021
1

How can I cast string to enum?

YourEnum foo = (YourEnum) Enum.Parse(typeof(YourEnum), yourString);
Posted by: Guest on July-01-2021

Code answers related to "enum convert back string to number"

C# Answers by Framework

Browse Popular Code Answers by Language