Home » C# programs » C# Data structure programs

C# program to insert or enqueue elements into queue using collection

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

Queue.Enqueue method

This is a method of 'Queue' class, it inserts an element to queue.

Syntax:

void Queue.Enqueue(object item);

Parameter(s):

item : item to be inserted into queue.

Program to insert element in queue using Enqueue method 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("Items are added or enqueued into Queue.");

        }
    }
}

Output

Items are added or enqueued into Queue.

In this program, we are adding 4 items into queue that 10,20,30,40 respectively by creating object of Queue class.

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.