Queue Collection Types

The System.Collections.Queue, System.Collections.Generic.Queue<T>, and System.Collections.Concurrent.ConcurrentQueue<T> classes are first-in, first-out collection classes that implement the ICollection interface and the ICollection<T> generic interface.

Queues and stacks are useful when you need temporary storage for information; that is, when you might want to discard an element after retrieving its value. Use Queue if you need to access the information in the same order that it is stored in the collection. Use Stack if you need to access the information in reverse order. Use ConcurrentQueue<T> or ConcurrentStack<T> if you need to access the collection from multiple threads concurrently.

Three main operations can be performed on a Queue and its elements:

  • Enqueue adds an element to the end of the Queue.

  • Dequeue removes the oldest element from the start of the Queue. The TryDequeue method returns false (False in Visual Basic) if the value could not be removed.

  • Peek returns the oldest element that is at the start of the Queue but does not remove it from the Queue.

See Also

Reference

Queue

System.Collections.Generic.Queue<T>

Stack

System.Collections.Generic.Stack<T>

ICollection

System.Collections.Generic.ICollection<T>

ConcurrentQueue<T>

ConcurrentStack<T>

System.Collections.Concurrent.IProducerConsumerCollection<T>

Other Resources

Commonly Used Collection Types

Thread-Safe Collections