It represents a first-in, first-out collection of object. It is used when you need a first-in, first-out access of items. When you add an item in the list, it is called enqueue, and when you remove an item, it is called deque
Properties and Methods of the Queue Class
The following table lists some of the commonly used properties of the Queueclass:
|Count||Gets the number of elements contained in the Queue.|
The following table lists some of the commonly used methods of the Queueclass:
|S.N||Method Name & Purpose|
|1||Public Overridable Sub Clear
Removes all elements from the Queue.
|2||Public Overridable Function Contains (obj As Object) As Boolean
Determines whether an element is in the Queue.
|3||Public Overridable Function Dequeue As Object
Removes and returns the object at the beginning of the Queue.
|4||Public Overridable Sub Enqueue (obj As Object)
Adds an object to the end of the Queue.
|5||Public Overridable Function ToArray As Object()
Copies the Queue to a new array.
|6||Public Overridable Sub TrimToSize
Sets the capacity to the actual number of elements in the Queue.
Finally following example demonstrate the use of Queue collection class:
When the above code is compiled and executed, it produces the following result: