stackvariableAs [New] Stack
stackvariable(required; Stack object)
The name of the Stack object
A Stack object is a model of a stack.
Succinctly put, a stack is a last-in, first-out data structure. (This is often abbreviated LIFO.) Put another way, a stack is a data structure that models a stack of items (like a stack of dinner plates). There is a method for inserting items at the top of the stack (pushing) as well as a method for removing the item that is currently at the top of the stack (popping). Under this scenario, the next item to be popped is the item that was placed in line last — hence the phrase, last-in, first-out.
Note that the elements in a Stack object are of type Object.
Stack class members marked with a plus sign (+) are discussed in detail in their own entries.
' Define a new stack Dim s As New Stack( ) ' Push some items onto the stack s.Push("Chopin") s.Push ("Mozart") s.Push ("Beethoven") ' Is an item in the stack? MsgBox("Beethoven in stack: " & CStr(s.Contains("Beethoven"))) ' Peek at the first (top) item on the stack MsgBox("First item in stack is: " & s.Peek.ToString) ' Send stack to an array and display all items Dim s() As Object = s.ToArray( ) Dim i As ...