- HTML Comments Tutorial | Convert Comments into HTML Codes
- Data Structure and Algorithms Tutorial | Ultimate Guide to Learn
- Gradle Tutorial | For Beginners [ STEP-IN ]
- Encapsulation In Java | Complete Tutorial With Examples
- What is Release Management? | A Comprehensive Tutorial for Beginners
- OOPs Concepts in Java | Learn from Basics with Examples
- The Top Basic Tools of Quality Tutorial | The Ultimate Guide
- Set Environment for C# – Learn How to Setup through this Tutorial
- C# Vs Java Tutorial | Overview and Key Difference
- List of IDEs to run C# Programs | Tutorial for Learning Path
- C Sharp Variables and Constants | The Ultimate Guide
- Unsafe Code in C-Sharp Tutorial | Everything You Need to Know
- Type Conversion Method in C# | A Complete Tutorial
- What Is Synchronization in c# Tutorial | The BEST Step-By-Step Guide
- Understanding Structures in C# | Learn in 1 Day FREE Tutorial
- Strings – C# Tutorial | A Definitive Programming Guide
- Static Keyword in C# Tutorial | Learn with Examples
- Stack Collection in C# Tutorial | A Definitive Guide for Beginners
- C# Sorted List Tutorial with Examples | Learn in 1 Day FREE
- C# Serialization Tutorial | Ultimate Guide to Learn [BEST & NEW]
- Regular Expression in C# Tutorial | Everything You Need to Know
- What is Reflection in C#? | Learn Now Tutorial
- Queue Collection in C# Tutorial | A Definitive Guide
- Properties in C# | The complete Tutorial
- C# Preprocessor Directives Tutorial | Learn in 1 Day FREE
- Polymorphism C# Tutorial | The Ultimate Guide
- C# Operators Tutorial | Learn Arithmetic, Comparison, Logical Concepts
- Namespaces – The complete C# Tutorial
- Multithreading in C# Tutorial | Learn With Examples and Advantages
- Methods – C# Tutorial | A Complete Programming Guide
- Linked List Implementation in C# Tutorial | Ultimate Guide to Learn [UPDATED]
- Introduction to C# Tutorial | Guide for Beginners
- What is Interface in C# | A Defined Free Tutorial
- C# Inheritance Tutorial | A Complete Free Tutorial
- Indexers in C# Tutorial | A Complete Programming Guide
- HashSet Collection in C# Tutorial | Complete Guide Tutorial For Free
- Generics in C# Tutorial | Learn Generic Classes and Methods
- Creating Your First C# Program Tutorial | Learn in 1 Day
- Basics of File Handling in C# Tutorial | The Ultimate Guide
- C# Exception Handling Tutorial | Learn with Best Practices
- Events – C# Tutorial | A Complete Programming Guide
- C# Enumerations Type Tutorial | Learn Everything about Enum
- Dictionary Collection in C# | Ultimate Guide to Learn [NEW & UPDATED]
- Delegates – C# Programming Guide | The Ultimate Guide for Beginners
- Understanding Decision Making Statements in C# | Learn Now Tutorial
- Classes and Objects – C# Fundamentals Tutorial
- C# BitArray Collection Tutorial | Learn in 1 Day FREE
- Attributes in C# Tutorial | Learn to work with attributes in C#
- C# Array Tutorial | Create, Declare, Initialize
- ArrayList Collection on in C# | A Complete tutorial For Beginners
- Anonymous Methods and Lambdas – C# Tutorial | A Complete Guide
- Abstraction in C# Tutorial – Learn the Abstract class and Interface
- Game Development using Unity 3D Tutorial | Ultimate Guide to Learn [UPDATED]
- C++ Reference Tutorial | A Comprehensive Guide for Beginners
- PHP vs Python | Which Is Better For Web Development
- C++ Constructors Tutorial: Types and Copy Constructors
- JavaScript Arrays Tutorial | Complete Beginner’s Guide
- What Is Maven | Maven Tutorial For Beginners
- Spring Tutorial | Perfect Guide for Beginners
- React Hooks Tutorial for Beginners | Ultimate Guide to Learn
- Python for Data Science Tutorial | Quickstart : A Complete Guide
- What is Golang? : A tutorial for beginners | Get started
- Hibernate Validator Tutorial | Learn in 1 Day FREE
- Postman Tutorial for Beginners: API Testing using Postman | A Complete Guide
- Akka Tutorial
- J2EE | Web Development Tutorial for Beginners
- Scala Exception Handling Tutorial | Learn in 1 Day [ STEP-IN ]
- Web development Tutorial
- Visual Studio Tutorial
- PyGame Tutorial
- Python Anaconda Tutorial
- Python Scikit-Learn Cheat Sheet Tutorial
- Mean Stack Tutorial
- Python Requests Tutorial
- Advanced Java Tutorial
- Spring Boot Microservices Tutorial
- Java Servlets Tutorial
- How to Install Pycharm
- Pycharm Tutorial
- Python Version Tutorial
- Python strings
- How to Download Python
- C Data Types Tutorial
- arrays in python
- Python While Loop Tutorial
- JAVA Tutorial
- Loops In C Tutorial
- Java File I/O Tutorial
- Variables in Python Tutorial
- Python Tutorial
- Python Pandas Cheat Sheet Tutorial
- Data Structures Cheat Sheet with Python Tutorial
- Python Tuples Tutorial
- Python If Else Statements Tutorial
- Python Functions Tutorial
- HTML Comments Tutorial | Convert Comments into HTML Codes
- Data Structure and Algorithms Tutorial | Ultimate Guide to Learn
- Gradle Tutorial | For Beginners [ STEP-IN ]
- Encapsulation In Java | Complete Tutorial With Examples
- What is Release Management? | A Comprehensive Tutorial for Beginners
- OOPs Concepts in Java | Learn from Basics with Examples
- The Top Basic Tools of Quality Tutorial | The Ultimate Guide
- Set Environment for C# – Learn How to Setup through this Tutorial
- C# Vs Java Tutorial | Overview and Key Difference
- List of IDEs to run C# Programs | Tutorial for Learning Path
- C Sharp Variables and Constants | The Ultimate Guide
- Unsafe Code in C-Sharp Tutorial | Everything You Need to Know
- Type Conversion Method in C# | A Complete Tutorial
- What Is Synchronization in c# Tutorial | The BEST Step-By-Step Guide
- Understanding Structures in C# | Learn in 1 Day FREE Tutorial
- Strings – C# Tutorial | A Definitive Programming Guide
- Static Keyword in C# Tutorial | Learn with Examples
- Stack Collection in C# Tutorial | A Definitive Guide for Beginners
- C# Sorted List Tutorial with Examples | Learn in 1 Day FREE
- C# Serialization Tutorial | Ultimate Guide to Learn [BEST & NEW]
- Regular Expression in C# Tutorial | Everything You Need to Know
- What is Reflection in C#? | Learn Now Tutorial
- Queue Collection in C# Tutorial | A Definitive Guide
- Properties in C# | The complete Tutorial
- C# Preprocessor Directives Tutorial | Learn in 1 Day FREE
- Polymorphism C# Tutorial | The Ultimate Guide
- C# Operators Tutorial | Learn Arithmetic, Comparison, Logical Concepts
- Namespaces – The complete C# Tutorial
- Multithreading in C# Tutorial | Learn With Examples and Advantages
- Methods – C# Tutorial | A Complete Programming Guide
- Linked List Implementation in C# Tutorial | Ultimate Guide to Learn [UPDATED]
- Introduction to C# Tutorial | Guide for Beginners
- What is Interface in C# | A Defined Free Tutorial
- C# Inheritance Tutorial | A Complete Free Tutorial
- Indexers in C# Tutorial | A Complete Programming Guide
- HashSet Collection in C# Tutorial | Complete Guide Tutorial For Free
- Generics in C# Tutorial | Learn Generic Classes and Methods
- Creating Your First C# Program Tutorial | Learn in 1 Day
- Basics of File Handling in C# Tutorial | The Ultimate Guide
- C# Exception Handling Tutorial | Learn with Best Practices
- Events – C# Tutorial | A Complete Programming Guide
- C# Enumerations Type Tutorial | Learn Everything about Enum
- Dictionary Collection in C# | Ultimate Guide to Learn [NEW & UPDATED]
- Delegates – C# Programming Guide | The Ultimate Guide for Beginners
- Understanding Decision Making Statements in C# | Learn Now Tutorial
- Classes and Objects – C# Fundamentals Tutorial
- C# BitArray Collection Tutorial | Learn in 1 Day FREE
- Attributes in C# Tutorial | Learn to work with attributes in C#
- C# Array Tutorial | Create, Declare, Initialize
- ArrayList Collection on in C# | A Complete tutorial For Beginners
- Anonymous Methods and Lambdas – C# Tutorial | A Complete Guide
- Abstraction in C# Tutorial – Learn the Abstract class and Interface
- Game Development using Unity 3D Tutorial | Ultimate Guide to Learn [UPDATED]
- C++ Reference Tutorial | A Comprehensive Guide for Beginners
- PHP vs Python | Which Is Better For Web Development
- C++ Constructors Tutorial: Types and Copy Constructors
- JavaScript Arrays Tutorial | Complete Beginner’s Guide
- What Is Maven | Maven Tutorial For Beginners
- Spring Tutorial | Perfect Guide for Beginners
- React Hooks Tutorial for Beginners | Ultimate Guide to Learn
- Python for Data Science Tutorial | Quickstart : A Complete Guide
- What is Golang? : A tutorial for beginners | Get started
- Hibernate Validator Tutorial | Learn in 1 Day FREE
- Postman Tutorial for Beginners: API Testing using Postman | A Complete Guide
- Akka Tutorial
- J2EE | Web Development Tutorial for Beginners
- Scala Exception Handling Tutorial | Learn in 1 Day [ STEP-IN ]
- Web development Tutorial
- Visual Studio Tutorial
- PyGame Tutorial
- Python Anaconda Tutorial
- Python Scikit-Learn Cheat Sheet Tutorial
- Mean Stack Tutorial
- Python Requests Tutorial
- Advanced Java Tutorial
- Spring Boot Microservices Tutorial
- Java Servlets Tutorial
- How to Install Pycharm
- Pycharm Tutorial
- Python Version Tutorial
- Python strings
- How to Download Python
- C Data Types Tutorial
- arrays in python
- Python While Loop Tutorial
- JAVA Tutorial
- Loops In C Tutorial
- Java File I/O Tutorial
- Variables in Python Tutorial
- Python Tutorial
- Python Pandas Cheat Sheet Tutorial
- Data Structures Cheat Sheet with Python Tutorial
- Python Tuples Tutorial
- Python If Else Statements Tutorial
- Python Functions Tutorial

Queue Collection in C# Tutorial | A Definitive Guide
Last updated on 16th Aug 2022, Blog, Software Engineering, Tutorials
C# Queue with Examples
In c#Queue is useful for representing a gathering of objects that saves elements in FIFO (First In, First Out) style, i.e
The element that is added first will come out first.
In a queue, elements are inserted from one end and removed from the other end.
Queues are useful when want to access elements from the collection in same order that is saved, And can store multiple null and duplicate values in a queue based on requirements.
Using Enqueue() and Dequeue() methods, can add or delete the element from the queue.
Here, the Enqueue() method is useful to add elements at end of the queue,
And the Dequeue() method is useful to remove elements from the queue.
Below is the pictorial representation of the queue process flow in the c# programming language.
C# Queue Declaration

c# will support both generic and non-generic kinds of queues.
Non -generic queue collections by using System.Collections namespace.
The collection is the class.
To explain a queue, you need to declare an instance of the queue class before performing any operations like add, delete, etc. as shown below.
Queue que = new Queue();
If you observe the above queue declaration, generate a new queue (que) with an instance of a queue class without specifying any size.
C# Queue Properties
The following are the commonly used properties of a queue in the c# programming language.
Property | Description |
---|---|
Count | It will return the total number of elements in queue |
IsSynchronized | It is used to get a value to denote that access to the queue is synchronized (thread-safe) or not. |
C# Queue Methods
Method | Description |
---|---|
Enqueue | It is used to add the elements at the end of the queue. |
Dequeue | It will remove and return an item from the starting of the queue. |
Clear | It will remove all elements from the queue. |
Clone | It will generate a shallow copy of the queue. |
Contains | It is used to find whether an element exists in a queue or not. |
Peek | It is used to get the first element from a queue. |
TrimToSize | It is used to set the capacity of the queue to an actual number of elements in the queue. |
C# Queue Example
ill use a non-generic type of queue to add elements of various data types to the queue using Enqueue() method.
Below is the example of adding and accessing elements of the queue in c#.
- using System;
- using System.Collections;
- namespace Tutlane
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Create and initialize a queue
- Queue que = new Queue();
- que.Enqueue(“Welcome”);
- que.Enqueue(“Tutlane”);
- que.Enqueue(20.5f);
- que.Enqueue(10);
- que.Enqueue(100);
- Console.WriteLine(“******Queue Example******”);
- Console.WriteLine(“Number of Elements in Queue: {0}”, que.Count);
- Console.WriteLine(“******Queue Elements******”);
- // Access Queue Elements
- foreach (var item in que)
- {
- Console.WriteLine(item);
- }
- Console.ReadLine();
- }
- }
- }
If we observe the above example, we generated a new queue (que).
We added various data type elements to the queue (que) using Enqueue() method, and used a for each loop to iterate through a queue to get elements from it.
C# Dequeue() Method to Access Queue Elements
The queue Dequeue() method will always remove and return a first element of the queue.
C# Peek() Method to Access Queue Elements
The queue Peek() method will always return the first element of the queue.
C# Queue Contains() Method
In c#, by using the queue Contains() method, can check if an element exists in a queue or not.
If the element is discovered in the queue, it will return true; otherwise, it will return false.
C# – Queue Class:
It represents a first-in, first out collection of the object.
It is used when needing a first-in, first-out access to the items.
When adding an item in the list, it is called enqueue, and when removing an item, it is called deque.
Methods and Properties of the Queue Class
The below table lists some of the commonly used properties of the Queue class
Sr.No | Property & Description |
---|---|
1 | Count Gets the number of the elements contained in the Queue. |
The below table lists some of the commonly used methods of the Queue class −
Sr.No | Property & Description |
---|---|
1 | public virtual void Clear(); Removes all the elements from the Queue. |
2 | public virtual bool Contains(object obj); Find whether an element is in the Queue. |
3 | public virtual object Dequeue(); Removes and returns an object at the beginning of the Queue. |
4 | public virtual void Enqueue(object obj); Adds an object to the end of the Queue. |
5 | public virtual object[] ToArray(); Copies the Queue to the new array. |
6 | public virtual void TrimToSize(); Sets the capacity to the actual number of elements in the Queue. |
Types of Queues:

Simple Queue:
It is also known as a linear queue is the most basic version of a queue.
Insertion of an element that is. The Enqueue operation takes place at the rear end and removal of an element ,that is the Dequeue operation takes place at the front end.
Circular Queue:
In a circular queue, the element of a queue acts as a circular ring.
The working of a circular queue is the same as the linear queue except for the fact that the last element is connected to the first element.
Its advantage is that the memory is utilized in a good way.
This is due to the fact that if there is an empty space, i.e. if no element is present at a specific point in the queue, an element may simply be inserted at that place.
Priority Queue:
This queue is a very special type of queue.
Its specialty is that it assembles the elements in a queue based on some priority.
The priority can be something where the element with the highest value has the priority so it makes a queue with decreasing order of values.
The priority can also be such that the element with the lowest value gets the highest priority so in turn it makes a queue with increasing order of values.
Dequeue:
Dequeue is also known as the Double Ended Queue.
Double ended, it means that an element can be inserted or removed from both the ends of the queue unlike the other queues in which it can be done only from the one end.
Because of this property it does not obey the First In First Out property.
Implementation of Queue:
Sequential allocation:
- An array can be used to implement a queue.
- It can organize a limited number of the elements.
Linked list allocation:
- A queue can be implemented by using a linked list.
- It can organize an unlimited number of the elements.
Applications of Queue:
Multi programming:
- Multiprogramming is when multiple programs are running in the main memory.
- It is needed to organize these multiple programs and these multiple programs are organized as queues.
Network:
- In a network, a queue is used in devices like a router or a switch.
- Another application of a queue is a mail queue which is a directory that saves data and controls files for mail messages.
Job Scheduling:
- The computer has a task to execute a specific number of jobs that are scheduled to be executed one after another.
- These jobs are assigned to the processor one by one which is organized by using a queue.
Shared resources:
- Queues are used as waiting lists for the single shared resource.
Real-time application of Queue:
- ATM Booth Line
- Ticket Counter Line
- Key press sequence on keyboard
- CPU task scheduling
- Waiting time of every customer at call centers.
Advantages of Queue:

Disadvantages of Queue:
- The operations like insertion and deletion of elements from the middle are time consuming. Limited Space.
- In a classical queue, a new element can only be inserted when the existing elements are deleted from a queue.
- Searching for an element takes O(N) the time.
- Maximum size of the queue must be defined prior.