Using the Stack class in .NET Part 3 – Peek and pop elements in the stack

Finally let’s peek and pop elements from our newly created stack.

Console.WriteLine("Popping '{0}'", numbers.Pop());
Console.WriteLine("Peeking '{0}'", numbers.Peek());   

As you can see you popped the last item of the stack which made so you could peek on the second added item.

Great work! Now go ahead and create some Stacks!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: