C# | Get the number of elements contained in the Queue Last Updated : 01 Feb, 2019 Comments Improve Suggest changes Like Article Like Report Queue represents a first-in, first out collection of object. It is used when you need a 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 deque. Queue.Count Property is used to get the number of elements contained in the Queue. Properties: Enqueue adds an element to the end of the Queue. Dequeue removes the oldest element from the start of the Queue. Peek returns the oldest element that is at the start of the Queue but does not remove it from the Queue. The capacity of a Queue is the number of elements the Queue can hold. As elements are added to a Queue, the capacity is automatically increased as required by reallocating the internal array. Queue accepts null as a valid value for reference types and allows duplicate elements. Syntax: myQueue.Count Here, myQueue is the name of the Queue. Return Value: This property returns the number of elements contained in the Queue. Example 1: CSHARP // C# code to Get the number of // elements contained in the Queue using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a Queue of strings Queue<string> myQueue = new Queue<string>(); // Inserting the elements into the Queue myQueue.Enqueue("Chandigarh"); myQueue.Enqueue("Delhi"); myQueue.Enqueue("Noida"); myQueue.Enqueue("Himachal"); myQueue.Enqueue("Punjab"); myQueue.Enqueue("Jammu"); // Displaying the count of elements // contained in the Queue Console.Write("Total number of elements in the Queue are : "); Console.WriteLine(myQueue.Count); } } Output: Total number of elements in the Queue are : 6 Example 2: CSHARP // C# code to Get the number of // elements contained in the Queue using System; using System.Collections.Generic; class GFG { // Driver code public static void Main() { // Creating a Queue of Integers Queue<int> myQueue = new Queue<int>(); // Displaying the count of elements // contained in the Queue Console.Write("Total number of elements in the Queue are : "); // The function should return 0 // as the Queue is empty and it // doesn't contain any element Console.WriteLine(myQueue.Count); } } Output: Total number of elements in the Queue are : 0 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.queue-1.count?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Get the number of elements contained in the Queue S Sahil_Bansall Follow Improve Article Tags : Misc C# CSharp-Generic-Queue CSharp-Collections-Namespace CSharp-Generic-Namespace +1 More Practice Tags : Misc Similar Reads C# | Get the number of elements contained in the Stack Stack represents a last-in, first out collection of object. Stack<T>.Count Property is used to gets the number of elements contained in the Stack. Retrieving the value of this property is an O(1) operation. Syntax: myStack.Count Here myStack is the name of the Stack<T> Return Value: The 2 min read C# | Get the number of elements in the SortedSet SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.Count Property is used to get the number of elements in the SortedSet. Properties: In C#, SortedSet class can be used to store, remove or view elemen 2 min read C# | Get the number of elements actually contained in the ArrayList ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searching and sorting items in the list. ArrayList.Count property gets the number of elements actually contained in 3 min read C# | Get the number of elements contained in Collection<T> Collection<T>.Count property is used to get the number of elements actually contained in the Collection<T>. Syntax: public int Count { get; } Return Value: The number of elements actually contained in the Collection<T>. Below given are some examples to understand the implementation 2 min read C# | Count the total number of elements in the List List class represents the list of objects which can be accessed by index. It comes under the System.Collection.Generic namespace. List class can be used to create a collection of different types like integers, strings etc. List class also provides the methods to search, sort, and manipulate lists. L 2 min read Like