Horje
C#: casting string to enum object Code Example
C# .net core convert string to enum
var foo = (YourEnum) Enum.Parse(typeof(YourEnum), yourString);
if (Enum.IsDefined(typeof(YourEnum), foo))
{
    return foo;
}
C#: casting string to enum object
public static T ToEnum<T>(this string value, T defaultValue) 
{
    if (string.IsNullOrEmpty(value))
    {
        return defaultValue;
    }

    T result;
    return Enum.TryParse<T>(value, true, out result) ? result : defaultValue;
}
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;
}




Csharp

Related
c# get folder of full ilepath Code Example c# get folder of full ilepath Code Example
c# datatable current row Code Example c# datatable current row Code Example
c# application exit Code Example c# application exit Code Example
how to fix error cs1513 in unity Code Example how to fix error cs1513 in unity Code Example
c# get string in parentheses Code Example c# get string in parentheses Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7