
But you also do things such as Print() all on your own. But I have noticed a pattern that if someone questions you on why you do some things a certain, you quickly take refuge under the blanket of that's what the exercise states. First let's state the good: you are performing such exercises to improve your C# and. You have posted several such exercises before, and I have commented on them as well. Thank you for all the help so far on this site. Is there anything left to improve on with this that is within the boundaries of what the instructions expect? Any advice or suggestions if anything to teach me something new would be great. Throw new InvalidOperationException("Stack is empty.") Throw new InvalidOperationException("Cannot use.

We should be able to use this stack class as follows: var stack = new Stack() The Clear() method removes all objects from the stack. Again, thinking of all these edge cases, separates Remember, your classes should always be inĪ valid state and used properly. In this case, this method should throw an Make sure to take into account the scenario that we call the Pop() The Pop() method removes the object on top of the stack and returns Should think of all possibilities and make sure the method behaves Null is passed to this method, you should throw an We should not store null references in the stack. Make sure to take into account the scenario that null is passed to So any types can be automatically upcast to the object. Remember the “object” class is the base of all classes in the.


The “object” type here so we can store any objects inside the stack. The Push() method stores the given object on top of the stack. A Stack is a data structure for storing a list of elements in a LIFO
