Sponsored Ad

Thursday, May 20, 2010

How to add and Remove items from Queue using C# | Queue Example

 

C# 2.0 collection classes contains the Queue collection to represent the queue, by using this class you can easily insert and remove the queue functionality. Please note that Queue works as FIFO(First in First out) basis.

 

Output of Queue program:

How to add and Remove items from Queue using C# | Queue Example

 

Source Code of Queue Program:

using System;
using System.Text;
using System.Collections;
namespace Console_App
{
    public class Class2
    {
        public static void Main()
        {
            Queue objQueue = new Queue();

            objQueue.Enqueue("String 1");
            objQueue.Enqueue(100);
            objQueue.Enqueue(99.99);

            Console.WriteLine(" Queue contents:");
            foreach (object temp in objQueue)
            {
                Console.WriteLine(temp);
            }

            Console.WriteLine(" Removing from Queue:");
            while (objQueue.Count != 0)
            {
                object temp = objQueue.Dequeue();
                Console.WriteLine(temp + " is removed from Queue");
            }

            Console.ReadLine();
        }
    }

}

No comments:

Post a Comment

Sponsored Ad

Development Updates