Queue in C#.net

Queue is a FIFO
collection. It processes elements in a first-in, first-out order.Objects stored in a
Queue are inserted at one end and removed from the other. The Queue provide
additional insertion, extraction, and inspection operations. We can Enqueue
(add) items in Queue and we can Dequeue (remove from Queue ) or we can Peek
(that is we will get the reference of first item ) item from Queue. Queue
accepts null reference as a valid value and allows duplicate elements.

The following table
lists some of the commonly used methods
of the Queue class

1

public virtual void Clear();
Removes all objects from the Queue.

2

public virtual void Clone ();
Creates a shallow copy of the Queue.

3

public virtual bool Contains( object obj );
Determines whether an element is in the Queue.

4

public virtual object Dequeue();
Removes and returns the object at the beginning of the Queue

5

public virtual void Enqueue( object obj );
Adds an object to the end of the Queue.

6

public
virtual Object Peek()

Returns the object at the beginning of the Queue without removing it.

7

public virtual object[] ToArray();
Copies the Queue elements to a new array.

8

public virtual void TrimToSize();
Sets the capacity to the actual number of elements in the Queue.