Home » VB.NET Queue

VB.NET Queue

In VB.NET, the Queue is used to store a collection of objects that follow FIFO (First In, First Out). Generally, the Queue class is provided by the VB .NET collection, which is useful for accessing elements from a collection of objects in the first-in-first-out style, which means the item inserted first in the queue will come out first from the queue. Furthermore, it uses Enqueue() and Dequeue() operation to insert and delete element from the collection of objects in Queue, where the Enqueue() operation is used to add elements at the end of the queue, and the Dequeue() operation is used to remove items starting from the queue.

The following is the pictorial representation of the Enqueue and Dequeue process in the VB.NET Queue.

VB.NET Queue

In this diagram, the Enqueue represents the Queue’s insertion, and the Dequeue represents the deletion of the items from the Queue.

Methods of VB.NET Queue

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

Method Name Description
Clear A Clear is used to remove all elements from the Queue.
Public Overridable Sub Clear
Contains It is used to validate whether a particular element exists in Queue or not.
Syntax: Queue.Contains(element)
Peek A Peek method is used to return the first element out of the Queue.
Syntax: Queue.Peek()
Dequeue It is used to remove an item from the starting of a Queue.
Syntax Queue.Dequeue()
Enqueue An Enqueue method is used to insert an item at the end of the Queue.
Syntax: Queue.Enqueue(item)

Let’s create a program to understand the various function of Queue in the VB.NET programming language.

Que_col.vb

Output:

VB.NET Queue


You may also like