I do understand how Stack()
and Stack
works, but I really can\'t see any scenarios where an array, List
or IEnumer
Ideally you use, or create as needed, classes that reflect how things work in the real world, the things you are modeling in code. Such classes give us a level of abstraction so we can code in terms of what we are modeling/simulating. Additionally when coding some complex thing, using a familiar paradigm helps. To wit: Oh, this Fuzzinator class uses a Stack. I know what a stack is and how it works.
Second, that higher-level-of-abstraction class gives us code that works (we assume the .NET framework was tested) and saves us the time and pain of re-inventing the wheel.
Third, the code is easier to read, easier to understand, easier to change and so on. It is more maintainable.
Using classes with more refined functionality helps limit how we might screw up in using it.
On the whole your application is simply better when it's coded at appropriate levels of abstraction.
Stack is one of these classes.
My HP-41X calculator does its arithmetic using a stack. This way of calculation is called RPN - Reverse Polish Notation.
If I were simulating a cafeteria the Stack would be perfect for that stack of plates. Plates get on and off the stack from the top. Not the middle, not the end; just the top. A Stack. I can only Push() and Pop() plates which makes the code more simple and clear.
Alternatively, imagine coding with the C# equivalent of sub-atomic particles - generic collection or generic IEnumerable, etc. I end up using general utility methods and properties with general names with multi-variable numbers of parameters which in the aggregate obscure the fact that I'm stacking plates.