how to compare string with enum in C#

You can use the Enum.TryParse() method to convert a string to the equivalent enumerated value (assuming it exists):

Name myName;
if (Enum.TryParse(nameString, out myName))
{
    switch (myName) { case John: ... }
}

Leave a Comment