1. Queue Definition
The System. Collections. Queue class indicates the object's first-in-first-out set. objects stored in the Queue are inserted at one end and removed from the other end.
2. Advantages
1. sequential processing of sets (first-in-first-out ).
2. elements that can accept null values and repeat are allowed.
3. Queue Constructor
Constructors
Note
Queue ()
Initialize a new instance of the Queue class. This instance is empty and has the default initial capacity (32) and uses the default growth factor (2.0 ).
Queue (ICollection)
Initializes a new instance of the Queue class. This instance contains elements copied from the specified set, has the same initial capacity as the number of copied elements, and uses the default growth factor.
Queue (Int32)
Initialize a new instance of the Queue class. This instance is empty and has the specified initial capacity and uses the default growth factor.
Queue (Int32, Single)
Initialize a new instance of the Queue class. This instance is empty and has the specified initial capacity and uses the specified growth factor.
4. Attributes of Queue
Attribute name
Note
Count
Obtains the number of elements contained in a Queue.
5. Queue Method
Method Name
Note
Void Clear ()
Remove all objects from the Queue.
Bool Contains (object obj)
Determine whether an element is in the Queue.
Object Clone ()
Create a superficial copy of the Queue.
Void CopyTo (Array array, int index)
Copy the Queue element from the specified Array index to the existing one-dimensional Array.
Object Dequeue ()
Remove and return the object at the beginning of the Queue.
Void Enqueue (object obj)
Add the object to the end of the Queue.
Object Peek ()
Returns the object at the beginning of the Queue, but does not remove it.
Object [] ToArray ()
Copy the Queue element to the new array.
Void TrimToSize ()
Set the capacity to the actual number of elements in the Queue.
6. Queue usage example
Code
Class Program
{
Static void Main (string [] args)
{
// Create a queue
Queue myQ = new Queue ();
MyQ. Enqueue ("The"); // enter The queue
MyQ. Enqueue ("quick ");
MyQ. Enqueue (