C#: Is there a way to classify enums?
c#, classification, enums
Solution
Why not KISS:
class PlayerPosition {
public enum Position {
Quarterback,
Runningback,
DefensiveEnd,
Linebacker
}
public enum Type {
Offense,
Defense
}
public static Type GetTypeForPosition(Position position) {
switch (position) {
case Quarterback:
case Runningback:
return Type.Offense;
case DefensiveEnd:
case Linebacker:
return Type.Defense;
}
}
}
Problem
Given the following enum: ``` public enum Position { Quarterback, Runningback, DefensiveEnd, Linebacker }; ``` Is it possible to classify the named constants, such that I could mark 'Quarterback' and 'Runningback' as offensive positions and 'DefensiveEnd' and 'Linebacker' as defensive positions?