 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove all objects from the Queue in C#
To remove all objects from the Queue, the code is as follows −
Example
using System; using System.Collections.Generic; public class Demo {    public static void Main(){       Queue<string> queue = new Queue<string>();       queue.Enqueue("Gary");       queue.Enqueue("Jack");       queue.Enqueue("Ryan");       queue.Enqueue("Kevin");       queue.Enqueue("Mark");       queue.Enqueue("Jack");       queue.Enqueue("Ryan");       queue.Enqueue("Kevin");       Console.Write("Count of elements = ");       Console.WriteLine(queue.Count);       queue.Clear();       Console.Write("Count of elements (updated) = ");       Console.WriteLine(queue.Count);    } }  Output
This will produce the following output −
Count of elements = 8 Count of elements (updated) = 0
Example
Let us see another example −
using System; using System.Collections.Generic; public class Demo {    public static void Main(){       Queue<string> queue = new Queue<string>();       queue.Enqueue("A");       queue.Enqueue("B");       queue.Enqueue("C");       queue.Enqueue("D");       queue.Enqueue("E");       Console.WriteLine("Count of elements = "+queue.Count);       queue.Clear();       Console.Write("Count of elements (updated) = "+queue.Count);    } }  Output
This will produce the following output −
Count of elements = 5 Count of elements (updated) = 0
Advertisements
 