Windows Phone Developers

Thursday, June 9, 2011

Queue in C# / Add and Remove items from Queue in C# (.NET)

Queues are common in real world - Flight checkins to School. Here is the way you can use it in C#

private static void CustomerServiceQueue()
        {
            Queue CSQ = new Queue();

            CSQ.Enqueue("Gautam");
            CSQ.Enqueue("Nargis");
            CSQ.Enqueue("Beth");
            CSQ.Enqueue("Slobodan");

            Console.WriteLine("Peeking Queue: {0}", CSQ.Peek());

            Console.WriteLine("Check if CSQ Contains Beth : {0}", CSQ.Contains("Beth"));

            while (CSQ.Count > 0)
            {
                Console.WriteLine(CSQ.Dequeue());
            }
           

        }

Contains checks for presence of the given object in the queue. Peek returns the first element from the queue

Dequeuue does the same as Peek, however, it also removes the object Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

No comments:

Post a Comment

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005