I am developing a card game.
I created a card collection that I use for two cases :
- A specific player cards.
- First package.
For the first use I need that the collection type will be List.
For the second use I need that the collection type will be Stack.
Is it possible to create a collection type that once will be a List and in
different use it will be a Stack?
Both card collcetions use have the same functions, that’s why I need this capability.
Just inherit from
List<T>and add thePushandPopmethods and you’re pretty much there.If you actually want to prevent List functionality (random access, etc) when it’s in “stack mode” then you’ll want to create an
IStack<T>interface and use it as anIStack<T>when you only want stack functionality.