Enum ToString with user friendly strings

后端 未结 23 1774
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 11:44

My enum consists of the following values:

private enum PublishStatusses{
    NotCompleted,
    Completed,
    Error
};

I want to be able to

23条回答
  •  隐瞒了意图╮
    2020-11-22 12:26

    Use Enum.GetName

    From the above link...

    using System;
    
    public class GetNameTest {
        enum Colors { Red, Green, Blue, Yellow };
        enum Styles { Plaid, Striped, Tartan, Corduroy };
    
        public static void Main() {
    
            Console.WriteLine("The 4th value of the Colors Enum is {0}", Enum.GetName(typeof(Colors), 3));
            Console.WriteLine("The 4th value of the Styles Enum is {0}", Enum.GetName(typeof(Styles), 3));
        }
    }
    // The example displays the following output:
    //       The 4th value of the Colors Enum is Yellow
    //       The 4th value of the Styles Enum is Corduroy
    

提交回复
热议问题