Home » C#.Net

Queue.Count property with example in C#

C# Queue.Count property: Here, we are going to learn about the Count property of Queue class in C#.
Submitted by IncludeHelp, on March 30, 2019

C# Queue.Count property

Queue.Count property is used to get total number of elements of a Queue.

Syntax:

    int Queue.Clear;

Parameters: None

Return value: int – it returns total number of elements of a Queue.

Example:

    declare and initialize a Queue:
    Queue que = new Queue();   

    insertting elements:
    que.Enqueue(100);
    que.Enqueue(200);
    que.Enqueue(300);
    que.Enqueue(400);
    que.Enqueue(500);
    
    printing length:
    que.Count;

    Output:
    5

C# example to get the total number of elements/objects of a Queue using Queue.Count property

using System;
using System.Text;
using System.Collections;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            //declare and initialize a Queue
            Queue que = new Queue();

            //insertting elements
            que.Enqueue(100);
            que.Enqueue(200);
            que.Enqueue(300);
            que.Enqueue(400);
            que.Enqueue(500);

            //printing length
            Console.WriteLine("Total elements: " + que.Count);

            //declaring another Queue
            Queue que1 = new Queue();

            //printing length
            Console.WriteLine("Total elements: " + que1.Count);

            //hit ENTER to exit
            Console.ReadLine();
        }
    }
}

Output

Total elements: 5
Total elements: 0

Reference: Queue.Count Property






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.