Created
January 13, 2018 08:25
-
-
Save GregTrevellick/5c48292bb704bc6378efc3fb44c3876d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class Program | |
{ | |
enum PetType | |
{ | |
None, | |
Cat = 1, | |
Dog = 2 | |
} | |
static void Main() | |
{ | |
// A. | |
// Possible user input: | |
string value = "Dog"; | |
// B. | |
// Try to convert the string to an enum: | |
PetType pet = (PetType)Enum.Parse(typeof(PetType), value); | |
// C. | |
// See if the conversion succeeded: | |
if (pet == PetType.Dog) | |
{ | |
Console.WriteLine("Equals dog."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment