Queue

Queue


Represents a first-in, first-out collection of values.


Implements:

ICloneable 
ICollection 
IEnumerable 
IObject 
IVersionable 

Public:

Properties:

NameDescription
 Count (get) Gets the number of elements contained in the Queue.  

Methods:

NameDescription
 Clear Removes all items from the Queue.  
 Clone Creates a shallow copy of the Queue.  
 Contains Determines whether an element is in the Queue.  
 CopyTo Copies the Queue elements to an existing one-dimensional array, starting at the specified array index.  
 Dequeue Removes and returns the item at the beginning of the Queue.  
 Enqueue Adds an item to the tail of the Queue, expanding the queue as necessary.  
 Equals Returns a boolean indicating if the value and this object instance are the same instance.  
 GetEnumerator Returns an enumerator for the queue.  
 GetHashCode Returns a pseudo-unique number identifying this instance.  
 Peek Returns the item at the beginning of the Queue without removing it.  
 ToArray Copies the Queue elements to a new array.  
 ToString Returns a string representation of this object instance.  
 TrimToSize Sets the capacity to the actual number of elements in the Queue.  

Remarks

Queues are useful for storing messages in the order they were received for sequential processing. This class implements a queue as a circular array. Values stored in a Queue are inserted at one end and removed from the other.

The capacity of a Queue is the number of elements the Queue can hold. As elements are added to a Queue, the capacity is automatically increased as required through reallocation. The capacity can be decreased by calling TrimToSize.

Examples

The following example shows how to create and add values to a Queue and how to print out its values.

Public Sub Main()
    ' Creates and initializesa new Queue.
    Dim MyQ As New Queue
    MyQ.Enqueue "Hello"
    MyQ.Enqueue "World"
    MyQ.Enqueue "!"
    
    ' Displays the properties and values of the Queue.
    Debug.Print "MyQ"
    Debug.Print "    Count:    " & MyQ.Count
    Debug.Print "   Values:";
    PrintValues MyQ
End Sub

Private Sub PrintValues(ByVal MyCollection As IEnumerable)
    Dim Item As Variant
    
    For Each Item In MyCollection
        Debug.Print "    " & Item;
    Next
    
    Debug.Print
End Sub

' The example code produces the following output.
'
'    MyQ
'        Count:    3
'       Values:    Hello    World    !

See Also

Project CorLib Overview

Class Queue Overview