Associating Additional Information with .NET Enum

后端 未结 5 1250
轻奢々
轻奢々 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:34

    One thing you could look at is the "Type-Safe Enum" pattern. This allows you to create an enum that is actually a full-fledged static object, which can have methods/properties/etc..

    http://www.javacamp.org/designPattern/enum.html

    Joshua Bloch talks about this pattern in his book "Effective Java." I've used it in a lot of different situations, and I actually prefer it over plain enums. (It's language-agnostic - it works in Java, C#, or pretty much any OO language).

提交回复
热议问题