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

CsharpProgrammingServer Side Programming

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
raja
Published on 07-Aug-2018 08:26:46
Advertisements