Last Updated : 11 Jul, 2025
Queue() Constructoris used to initializes a new instance of the Queue class which will be empty, and will have the default initial capacity, and uses the default growth factor. Queue represents a first-in, first out collection of object. It is used when you need first-in, first-out access of items. When you add an item in the list, it is called enqueue, and when you remove an item, it is called dequeue. This class comes under
System.Collectionsnamespace and implements ICollection, IEnumerable, and ICloneable interfaces.
Syntax:public Queue ();Important Points:
// C# Program to illustrate how
// to create a Queue
using System;
using System.Collections;
class Geeks {
// Main Method
public static void Main(String[] args)
{
// qt is the Queue object
// Queue() is the constructor
// used to initializes a new
// instance of the Queue class
Queue qt = new Queue();
// Count property is used to get the
// number of elements in Queue
// It will give 0 as no elements
// are present currently
Console.WriteLine(qt.Count);
}
}
Example 2: csharp
// C# Program to illustrate how
// to create a Queue
using System;
using System.Collections;
class Geeks {
// Main Method
public static void Main(String[] args)
{
// qt is the Queue object
// Queue() is the constructor
// used to initializes a new
// instance of the Queue class
Queue qt = new Queue();
Console.Write("Before Enqueue Method: ");
// Count property is used to get the
// number of elements in Queue
// It will give 0 as no elements
// are present currently
Console.WriteLine(qt.Count);
// Inserting the elements
// into the Queue
qt.Enqueue("This");
qt.Enqueue("is");
qt.Enqueue("how");
qt.Enqueue("to");
qt.Enqueue("create");
qt.Enqueue("Queue");
qt.Enqueue("in");
qt.Enqueue("C#");
Console.Write("After Enqueue Method: ");
// Count property is used to get the
// number of elements in qt
Console.WriteLine(qt.Count);
}
}
Output:
Before Enqueue Method: 0 After Enqueue Method: 8Reference:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4