How do you access the top element in a Stack<T> without removing it?
Use the Peek() method.
Example:
int top = stack.Peek();
Follow:
This is useful when you just want to inspect the top element without altering the stack.
Use the Peek() method.
Example:
int top = stack.Peek();
Follow:
This is useful when you just want to inspect the top element without altering the stack.