- Home /
Converting from String to Enum
Hi! I want to convert from String to Enum, but I am getting error.. I looked here Converting a string to an enum and used the same syntax C#,
selectedPetName = System.Enum.Parse (typeof(PetName), someText);
Here selectedPetName if of type PetName, and the error that I'm getting is
error CS0266: Cannot implicitly convert type
object' to
GameManager.PetName'. An explicit conversion exists (are you missing a cast?)
I also tried to putting as PetName but error remains.
Answer by robhuhn · Apr 15, 2014 at 07:39 AM
Since Enum.Parse returns an Object it should be
selectedPetName = (PetName) System.Enum.Parse (typeof(PetName), someText);
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
NPC Class looking for help 1 Answer
Multiple Cars not working 1 Answer
How would you convert ogg files to wav files properly using C# scripting? 1 Answer
A node in a childnode? 1 Answer