

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
Get the number of elements contained in the Queue in C#
To get the number of elements contained in 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); } }
Output
This will produce the following output −
Count of elements = 5
- Related Questions & Answers
- Get the number of elements contained in the Stack in C#
- Get the number of elements contained in SortedList in C#
- Get the number of elements contained in Collection in C#
- Get the number of elements actually contained in the ArrayList in C#
- Number of elements contained in the BitArray in C#?
- Get the number of nodes contained in LinkedList in C#
- Get the number of key/value pairs contained in ListDictionary in C#
- Get the number of key/values pairs contained in OrderedDictionary in C#
- Clearing the elements of the Queue in Javascript
- Get the number of elements in the SortedSet in C#
- Get the number of elements of the Masked Array in Numpy
- Get or set the number of elements in the BitArray in C#
- Get the object at the beginning of the Queue – Peek Operation in C#
- What are the inserting elements in queue in C language?
- Get or set the number of elements that the ArrayList can contain in C#
Advertisements