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

前端 未结 13 2615
迷失自我
迷失自我 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:30

    The default is the first one in the definition. For example:

    public enum MyEnum{His,Hers,Mine,Theirs}
    
    Enum.GetValues(typeOf(MyEnum)).GetValue(0);
    

    This will return His

提交回复
热议问题