c#enum描述度

时间:2015-10-06 07:58:21

标签: c# .net enums

如何在枚举中声明°而不是度?

//tilts declaration
    public enum Tilts
    {
        mm = 0,
        ° = 1, //degree
        inch = 2
    }

1 个答案:

答案 0 :(得分:0)

要跟进我的评论,您可能应该在enum添加扩展方法,以提供您需要的格式化字符串:

public enum Tilts
{
    Mm = 0,
    Degree = 1,
    Inch = 2
}

public static class TiltsExtensions
{
    public static string ToSymbol(this Tilts tilts)
    {
        switch (tilts)
        {
            default: return tilts.ToString();
            case Tilts.Degree: return "°";
            // etc;
        }
    }
}

然后,只要您想输出符号形式,只需使用如下方法:

Console.WriteLine(tilts.ToSymbol());
相关问题