I'm trying to build generic function that get from user string and try to parse it to Enum valuse like this:
private Enum getEnumStringEnumType(Type i_EnumType)
{
string userInputString = string.Empty;
Enum resultInputType;
bool enumParseResult = false;
while (!enumParseResult)
{
userInputString = System.Console.ReadLine();
enumParseResult = Enum.TryParse(userInputString, true, out resultInputType);
}
}
But i get:
The type 'System.Enum' must be a non-nullable value type in order to use it as parameter 'TEnum' in the generic type or method 'System.Enum.TryParse<TEnum>(string, bool, out TEnum) .
The Error means that i need to decalare a specific Enum for resultInputType? How can I fix this ? Thanks.
question from:https://stackoverflow.com/questions/10685794/how-to-use-generic-tryparse-with-enum