Queue.Count Property in C#
Last Updated :
04 Feb, 2019
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:
using System;
using System.Collections;
class GFG {
public static void Main()
{
Queue myQueue = new Queue();
Console.Write( "Total number of elements" +
" in the Queue are : " );
Console.WriteLine(myQueue.Count);
}
}
|
Output:
Total number of elements in the Queue are : 0
Example 2:
using System;
using System.Collections;
class GFG {
public static void Main()
{
Queue myQueue = new Queue();
myQueue.Enqueue( "C" );
myQueue.Enqueue( "C++" );
myQueue.Enqueue( "Java" );
myQueue.Enqueue( "C#" );
myQueue.Enqueue( "HTML" );
myQueue.Enqueue( "CSS" );
Console.Write( "Total number of elements " +
"in the Queue are : " );
Console.WriteLine(myQueue.Count);
}
}
|
Output:
Total number of elements in the Queue are : 6
Reference:
Share your thoughts in the comments
Please Login to comment...