The Stack Collection

The System.Collections.Stack collection mimics the same-named memory area and works according to the LIFO (Last-In, First-Out) paradigm, meaning that the last item you add to the collection is the first that is pulled out from the collection. Stack exposes three important methods: Push adds an item to the collection, Pop enables the consuming of and removing of an item from the collection, and Peek returns the top item in the collection without removing it. The following is an example:

Dim s As New Stacks.Push(1)s.Push(2)'Returns 2 and leaves it in the collectionConsole.WriteLine(s.Peek)'Returns 2 and removes itConsole.WriteLine(s.Pop)'Returns 1 and removes itConsole.WriteLine(s.Pop)

As for ...

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.