C# Converting a String to Enum

Converting a string to Enum in c# is as follows:

object Enum.Parse(System.Type enumType, string value, bool ignoreCase);

You can then cast the object to some enum you desire.

Example:

Enum Direction
{
North,
South,
East,
West
}

var dat = (Direction) Enum.Parse(typeof(Direction), “North”);

Quite easy right? and you don’t need many if statements to convert a string to Enum.