This property is used to get the number of elements contained in the Queue. Retrieving the value of this property is an O(1) operation and it comes under the System.Collections namespace.
Syntax:
public virtual int Count { get; }
Property Value: This property returns the number of elements contained in the Queue.
Below programs illustrate the use of the above-discussed property:
Example 1:
// C# code to illustrate the // Queue.Count Property using System; using System.Collections; class GFG { // Driver code public static void Main() { // Creating a Queue Queue myQueue = new Queue(); // 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); } } |
chevron_right
filter_none
Output:
Total number of elements in the Queue are : 0
Example 2:
// C# code to illustrate the // Queue.Count Property using System; using System.Collections; class GFG { // Driver code public static void Main() { // Creating a Queue Queue myQueue = new Queue(); // Inserting the elements into the Queue myQueue.Enqueue("C"); myQueue.Enqueue("C++"); myQueue.Enqueue("Java"); myQueue.Enqueue("C#"); myQueue.Enqueue("HTML"); myQueue.Enqueue("CSS"); // Displaying the count of elements // contained in the Queue Console.Write("Total number of elements "+ "in the Queue are : "); Console.WriteLine(myQueue.Count); } } |
chevron_right
filter_none
Output:
Total number of elements in the Queue are : 6
Reference:
Recommended Posts:
- StringBuilder.Chars[] Property in C#
- Thread.CurrentThread Property in C#
- C# | OrderedDictionary.Item[Object] Property
- C# | LongLength property of an Array
- C# | Dictionary.Item[] Property
- C# | Dictionary.Values Property
- C# | Dictionary.Keys Property
- C# | Dictionary.Count Property
- C# | SortedDictionary.Item[] Property
- C# | SortedDictionary.Count Property
- C# | SortedDictionary.Keys Property
- C# | SortedDictionary.Values Property
- Queue.IsSynchronized Property in C#
- Stack.Count Property in C#
- Stack.IsSynchronized Property in C#
- Console.KeyAvailable() Property in C#
- Console.TreatControlCAsInput Property in C# with examples
- How to use AcceptsReturn Property of TextBox in C#?
- How to use AutoCheck property of CheckBox in C#?
- Uri.IsLoopback Property in C# with Example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

