C# Queue Queue(Int32)

Description

Queue Queue (Int32) initializes a new instance of the Queue class that is empty and has the specified initial capacity.

Syntax


public Queue(
  int capacity
)

Parameters

  • capacity - The initial number of elements that the Queue can contain.

Example


using System;/*from   w w  w .j av  a 2  s  .c o m*/
using System.Collections.Generic;

class Example
{
    public static void Main()
    {
        Queue<string> numbers = new Queue<string>(21);
        numbers.Enqueue("one");
        numbers.Enqueue("two");
        numbers.Enqueue("three");
        numbers.Enqueue("four");
        numbers.Enqueue("five");

        Queue<string> queueCopy = new Queue<string>(numbers.ToArray());

        foreach( string number in queueCopy )
        {
            Console.WriteLine(number);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack