Advertisement
Guest User

Untitled

a guest
Aug 13th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. string pet = "Dog";
  2. PetType petType = (PetType)Enum.Parse(typeof(PetType), pet);
  3. int petValue = (int)petType;
  4.    
  5. PetType result;
  6. if (Enum.TryParse<PetType>(pet, out result))
  7.     return (int)result;
  8. else
  9.     throw something with an error message
  10.    
  11. (PetType)Enum.Parse(typeof(PetType), pet)
  12.    
  13. PetType petTypeA = (PetType)Enum.Parse(typeof(PetType), "Dog");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement