Enum ToString with user friendly strings

后端 未结 23 2083
伪装坚强ぢ
伪装坚强ぢ 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:31

    According to this documentation: https://docs.microsoft.com/pt-br/dotnet/api/system.enum.tostring?view=netframework-4.8

    It is possible to just convert a enumerator to string using a format like this:

    public enum Example
    {
        Example1,
        Example2
    }
    
    Console.WriteLine(Example.Example1.ToString("g"));
    
    //Outputs: "Example1"
    

    You can see all the possible formats in this link: https://docs.microsoft.com/pt-br/dotnet/api/system.string?view=netframework-4.8

提交回复
热议问题