What is the Count property of Queue class in C#?


Use the Count property to find the count of elements of the Queue class. Set elements like the following declaration −

Queue q = new Queue();

q.Enqueue(1);
q.Enqueue(2);
q.Enqueue(3);
q.Enqueue(4);

Then use the Count property to count the elements −

q.Count

The following is an example showing how to work with Count property in Queue Class −

Example

 Live Demo

using System;
using System.Collections;

namespace Demo {
   class Program {
      static void Main(string[] args) {
         Queue q = new Queue();

         q.Enqueue(1);
         q.Enqueue(2);
         q.Enqueue(3);
         q.Enqueue(4);

         Console.WriteLine("Total elements: {0} ", q.Count);
   
         Console.ReadKey();
      }
   }
}

Output

Total elements: 4

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 20-Jun-2020

77 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements