Nested Enum and Property Naming Conflicts

后端 未结 7 836
孤城傲影
孤城傲影 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:06

    I would agree with moving the enum definition to a separate place. Currently, the enums are only visible through card, so if you wanted to check for an ace, you would have to do

    if (card.CardSuit == Card.Suit.Ace) { }  //need different name for Suit field
    

    Where if you moved it to a separate definition, you could do this if you made it global:

    if (card.Suit == Suit.Ace) { } //no naming clashes, easier to read
    

提交回复
热议问题