Reputation: 336
I am developing a card game. I created a card collection that I use for two cases :
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.
Upvotes: 2
Views: 74
Reputation: 31596
Just inherit from List<T>
and add the Push
and Pop
methods 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 an IStack<T>
when you only want stack functionality.
Upvotes: 1