Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

C#: casting string to enum object

public static TEnum ParseEnum<TEnum>(string value) where TEnum : struct
{
    TEnum tmp; 
    if (!Enum.TryParse<TEnum>(value, true, out tmp))
    {
        tmp = new TEnum();
    }
    return tmp;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #casting #string #enum #object
ADD COMMENT
Topic
Name
9+9 =