Choosing the default value of an Enum type without having to change values

前端 未结 13 2574
迷失自我
迷失自我 2020-12-04 07:46

In C#, is it possible to decorate an Enum type with an attribute or do something else to specify what the default value should be, without having the change the values? The

13条回答
  •  自闭症患者
    2020-12-04 08:26

    One more way that might be helpful - to use some kind of "alias". For example:

    public enum Status
    {
        New = 10,
        Old = 20,
        Actual = 30,
    
        // Use Status.Default to specify default status in your code. 
        Default = New 
    }
    

提交回复
热议问题