Associating Additional Information with .NET Enum

后端 未结 5 1345
轻奢々
轻奢々 2021-02-01 04:51

My question is best illustrated with an example.

Suppose I have the enum:

public enum ArrowDirection
{
    North,
    South,
    East,
    West
}
         


        
5条回答
  •  天命终不由人
    2021-02-01 05:35

    Your static method approach seems quite clean to me. You encapsulate both the enum and the static method within the same class. Changes to the enum are centralised within that single class.

    Adding a method to the enumeration (as per Java) seems to add complexity to something that is really a very simple concept.

    The attribute based approach is interesting, but once again seems to overcomplicate things when compared to a static method.

提交回复
热议问题