C# Queue Methods

Beginner
5 min read
Updated: Nov 2026
12 method guides
Method index

About This Index

This page is the C# Queue Methods index. Each row links to a full guide with syntax, parameters, return value, three examples, and FAQs. Examples use small fixed data such as Queue<int> and Queue<string>. A queue always keeps a fixed order (front to back), so the examples can print items directly and the output you see is the output you get.

Learn what a Queue is for on /c-sharp/queue. Use this page when you need a specific API such as Enqueue(), Dequeue(), or TryDequeue().

First in, first out.

A queue is a line. Enqueue adds at the back, Dequeue removes from the front, and Peek reads the front. Calling Dequeue or Peek on an empty queue throws, so check Count or use TryDequeue / TryPeek.

How to Call a Queue Method

Every Queue method is an instance method, so you call it on your queue variable:

C#
Queue<string> line = new Queue<string>();
line.Enqueue("Asha");                 // add at the back
line.Enqueue("Ben");
string next = line.Peek();            // look at the front: "Asha"
string served = line.Dequeue();       // remove from the front: "Asha"
bool has = line.Contains("Ben");      // search the whole queue
string[] copy = line.ToArray();       // copy front to back
int waiting = line.Count;             // 1

C# Queue Methods Table

All method guides in this C# tutorial series (12 tutorials), grouped by purpose.

Add / remove

4 methods

Put items at the back, take them from the front, or empty the whole queue. TryDequeue does the removal without throwing on an empty queue.

MethodDescriptionTutorial
Enqueue()Add an item at the back of the queue, so it waits behind everything already there.Try it
Dequeue()Remove and return the item at the front of the queue; throws if the queue is empty.Try it
TryDequeue()Try to remove the front item; returns true or false instead of throwing on an empty queue.Try it
Clear()Remove every item from the queue in one call; Count becomes 0.Try it

Look

3 methods

See the front item without removing it, or ask whether an item is anywhere in the queue.

MethodDescriptionTutorial
Peek()Read the item at the front of the queue without removing it; throws if the queue is empty.Try it
TryPeek()Try to read the front item without removing it; returns false instead of throwing on an empty queue.Try it
Contains()Check whether an item is anywhere in the queue; it scans from the front, so it is O(n).Try it

Copy / convert

2 methods

Copy the items, front to back, into a new array or into an array you already have.

MethodDescriptionTutorial
ToArray()Copy the queue into a new array, front to back. The queue itself is not changed.Try it
CopyTo()Copy the queue's items into an existing array, starting at a position you choose.Try it

Loop

1 method

Walk through the queue from front to back without removing anything.

MethodDescriptionTutorial
GetEnumerator()Get an enumerator that walks the queue from front to back; foreach uses it for you.Try it

Capacity

2 methods

Reserve space before a big load, or give back unused space after a big clean-up.

MethodDescriptionTutorial
EnsureCapacity()Pre-size the queue so it can hold at least a number of items without growing again.Try it
TrimExcess()Give back unused space after a queue shrinks; the items and their order stay the same.Try it

Frequently Asked Questions

They are the methods on System.Collections.Generic.Queue<T>. They add items at the back, remove items from the front, look at the front, check for an item, copy the items to an array, loop through them, and manage capacity.
This index lists 12 guides: Enqueue, Dequeue, TryDequeue, Clear, Peek, TryPeek, Contains, ToArray, CopyTo, GetEnumerator, EnsureCapacity, and TrimExcess.
Enqueue, Dequeue, TryDequeue, and Clear change the items. EnsureCapacity and TrimExcess change only the hidden storage size. Peek, TryPeek, Contains, ToArray, CopyTo, and GetEnumerator only read the queue.
First in, first out (FIFO). Dequeue, foreach, ToArray, and CopyTo all go from the front (the oldest item) to the back (the newest). Unlike a HashSet, this order is fixed.
Read the C# Queue hub first. Then open Enqueue(), Dequeue(), Peek(), and TryDequeue() from the tables below.

Start with Enqueue()

Join the line: add your first items at the back of a queue and see how the order is kept.

Enqueue() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful