Javatpoint Logo
Javatpoint Logo

VB.NET Stack

The stack is a homogeneous collection of elements used to store elements based on LIFO (Last-In First-Out). Generally, the stack is useful for accessing elements from a collection of objects in the Last-In First-Out style. Furthermore, it uses push and pop operations to get an insert element in the collection. Push operation is used to insert items into the stack, and pop operation is used to retrieve items from the stack. The last added item in the stack is retrieved first.

The following figure represents the push and pop operation in the VB.NET Stack.

VB.NET Stack

In the above diagram, the Pop represents the retrieval of the last item (4) from the stack, and the Push represents the insertion of the item in the Stack.

Methods in VB.NET Stack

The following are the most commonly used methods of the Stack in VB.NET.

Method Name Description
Clear The Clear method is used to remove all elements from the Stack.
Syntax: Public Overridable Sub Clear
Contains It is used to check whether the element exists or not in Stack.
Syntax: Stack.Contains(element)
Peek The Peek method is used to return an element at the top of the elements in Stack.
Pop It is used to remove an item that' added to the last in Stack.
Syntax: Stack.Pop()
Push A Push method is used to insert an item at the top of the Stack.
Syntax: Stack.Push(item)
ToArray The ToArray method is used to create a copy of the Stack.

Let's create a program to understand the various operation of Stack in the VB.NET programming language.



VB.NET Stack

In the above program, we have used various methods of Stack class such as Push() method is used to insert the elements into the Stack. The Contains() method is used to check whether the particular element exists or not, Peep() method is used to put the particular element at the top of all elements in the stack, and the Pop() method is used to remove the elements from the Stack.

Next TopicVB.NET Arrays

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA