How to define an enum with string value?

后端 未结 18 1422
一生所求
一生所求 2020-12-12 14:53

I am trying to define an Enum and add valid common separators which used in CSV or similar files. Then I am going to bind it to a ComboBox as a dat

18条回答
  •  被撕碎了的回忆
    2020-12-12 15:05

    Enumaration Class

     public sealed class GenericDateTimeFormatType
        {
    
            public static readonly GenericDateTimeFormatType Format1 = new GenericDateTimeFormatType("dd-MM-YYYY");
            public static readonly GenericDateTimeFormatType Format2 = new GenericDateTimeFormatType("dd-MMM-YYYY");
    
            private GenericDateTimeFormatType(string Format)
            {
                _Value = Format;
            }
    
            public string _Value { get; private set; }
        }
    

    Enumaration Consuption

    public static void Main()
    {
           Country A = new Country();
    
           A.DefaultDateFormat = GenericDateTimeFormatType.Format1;
    
          Console.ReadLine();
    }
    

提交回复
热议问题