String representation of an Enum

后端 未结 30 2344
不思量自难忘°
不思量自难忘° 2020-11-22 02:44

I have the following enumeration:

public enum AuthenticationMethod
{
    FORMS = 1,
    WINDOWSAUTHENTICATION = 2,
    SINGLESIGNON = 3
}

T

30条回答
  •  甜味超标
    2020-11-22 03:08

    Use method

    Enum.GetName(Type MyEnumType,  object enumvariable)  
    

    as in (Assume Shipper is a defined Enum)

    Shipper x = Shipper.FederalExpress;
    string s = Enum.GetName(typeof(Shipper), x);
    

    There are a bunch of other static methods on the Enum class worth investigating too...

提交回复
热议问题