String representation of an Enum

后端 未结 30 1935
不思量自难忘°
不思量自难忘° 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

    old post but...

    The answer to this may actually be very simple. Use Enum.ToString() function

    There are 6 overloads of this function, you can use Enum.Tostring("F") or Enum.ToString() to return the string value. No need to bother with anything else. Here is a working Demo

    Note that this solution may not work for all compilers (this demo does not work as expected) but at least it works for the latest compiler.

提交回复
热议问题