Nested Enum and Property Naming Conflicts

后端 未结 7 845
孤城傲影
孤城傲影 2021-02-06 23:48

There are some related questions here and here, but they didn\'t really give me satisfactory answers. The problem is that enums nested in a class in C# cannot have the same name

7条回答
  •  日久生厌
    2021-02-07 00:11

    I prefer to name enums using a noun followed by Options. In your case:

    SuitOptions
    RankOptions
    

    After all, the enum is just a set of possible options, right?

    You will have then:

    myCard.Suit = Card.SuitOptions.Clubs;
    

    Which in my opinion makes sense and you are still able to know when viewing the text whether is then enum or property.

提交回复
热议问题