IT. Expert System.

C#

Queue Class


It represents a first-in, first out collection of object. It is used when you need a first-in, first-out access of items. When you add an item in the list, it is called enqueue, and when you remove an item, it is called deque.

Methods and Properties of the Queue Class

The following table lists some of the commonly used properties of the Queue class:

PropertyDescription
CountGets the number of elements contained in the Queue.

The following table lists some of the commonly used methods of the Queue class:

S.NMethod Name & Purpose
1public virtual void Clear();
Removes all elements from the Queue.
2public virtual bool Contains( object obj );
Determines whether an element is in the Queue.
3public virtual object Dequeue();
Removes and returns the object at the beginning of the Queue.
4public virtual void Enqueue( object obj );
Adds an object to the end of the Queue.
5public virtual object[] ToArray();
Copies the Queue to a new array.
6public virtual void TrimToSize();
Sets the capacity to the actual number of elements in the Queue.

Example:

The following example demonstrates use of Stack:

using System;
using System.Collections;

namespace CollectionsApplication
{
   class Program
   {
      static void Main(string[] args)
      {
         Queue q = new Queue();

         q.Enqueue('A');
         q.Enqueue('M');
         q.Enqueue('G');
         q.Enqueue('W');
         
         Console.WriteLine("Current queue: ");
         foreach (char c in q)
            Console.Write(c + " ");
         Console.WriteLine();
         q.Enqueue('V');
         q.Enqueue('H');
         Console.WriteLine("Current queue: ");         
         foreach (char c in q)
            Console.Write(c + " ");
         Console.WriteLine();
         Console.WriteLine("Removing some values ");
         char ch = (char)q.Dequeue();
         Console.WriteLine("The removed value: {0}", ch);
         ch = (char)q.Dequeue();
         Console.WriteLine("The removed value: {0}", ch);
         Console.ReadKey();
      }
   }
}

When the above code is compiled and executed, it produces the following result:

Current queue: 
A M G W 
Current queue: 
A M G W V H 
Removing values
The removed value: A
The removed value: M


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 392 / 158675200. Delta: 0.00321 с