Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Convert Enum to String using C#

/// <summary>
/// 05/12/2022 Mahesh Kumar Yadav
/// Convert Enum to String
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value"></param>
/// <returns></returns>
public static string ToString<T>(T value) where T : struct
{
    if (!typeof(T).IsEnum)
    {
        throw new ArgumentException();
    }

    var fieldName = Enum.GetName(typeof(T), value);
    return fieldName ?? string.Empty;
}
 
PREVIOUS NEXT
Tagged: #Convert #Enum #String
ADD COMMENT
Topic
Name
6+7 =