String representation of an Enum

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

    If you've come here looking to implement a simple "Enum" but whose values are strings instead of ints, here is the simplest solution:

        public sealed class MetricValueList
        {
            public static readonly string Brand = "A4082457-D467-E111-98DC-0026B9010912";
            public static readonly string Name = "B5B5E167-D467-E111-98DC-0026B9010912";
        }
    

    Implementation:

    var someStringVariable = MetricValueList.Brand;
    

提交回复
热议问题