The key is an enumeration, so you can parse it like any enumeration:
string str = ; Key key; if(Enum.TryParse(str, true, out key)) {
Keep in mind that the string must match exactly (well, almost, this is a case-insensitive comparison due to this parameter true ) the name of the enumeration value.
source share