Home » C# programs » C# Data structure programs

C# program to delete or dequeue elements from queue using collection

In this C# program, we will learn how to delete or dequeue elements from queue using collection? Here we use Dequeue method of Queue class.
Submitted by IncludeHelp, on November 23, 2017

Queue.Dequeue() method

This is a method of 'Queue' class, it deletes an element from queue.

Syntax:

void Queue.Dequeue();

Return value:

This method returns deleted item from Queue.

Program to delete an element from a Queue in C#

using System;
using System.Collections;

namespace ConsoleApplication1
{
    
    class Program
    {
        static void Main()
        {
            Queue Q = new Queue(5);

            Q.Enqueue(10);
            Q.Enqueue(20);
            Q.Enqueue(30);
            Q.Enqueue(40);

            Console.WriteLine("Deleted item is: " + Q.Dequeue());
            Console.WriteLine("Deleted item is: " + Q.Dequeue());
            Console.WriteLine("Deleted item is: " + Q.Dequeue());

        }
    }
}

Output

Deleted item is: 10
Deleted item is: 20
Deleted item is: 30

In this program, we are inserting 4 items into Queue, than deleting 3 items from Queue using Dequeue() method.

Note: In above program, to use 'Queue' class, we need to include System.Collection namespace.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




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.