C# Queue CopyTo

Description

Queue CopyTo copies the Queue elements to an existing one-dimensional Array, starting at the specified array index.

Syntax

Queue.CopyTo has the following syntax.


public void CopyTo(
  T[] array,
  int arrayIndex
)

Parameters

Queue.CopyTo has the following parameters.

  • array - The one-dimensional Array that is the destination of the elements copied from Queue . The Array must have zero-based indexing.
  • arrayIndex - The zero-based index in array at which copying begins.

Example


using System;/*from  ww  w  .  ja  va2 s  .co m*/
using System.Collections;
using System.Collections.Generic;

class Sample
{
    public static void Main()
    {
        //Create a List of Strings
        //String-typed list
        Queue<string> words = new Queue<string>();

        words.Enqueue("A");
        words.Enqueue("B");
        words.Enqueue("C");
        words.Enqueue("D");
        words.Enqueue("E");
        words.Enqueue("F");


        string[] wordsArray = words.ToArray();  // Creates a new typed array

        // Copy first two elements to the end of an existing array:
        string[] existing = new string[1000];
        words.CopyTo(existing,0);
    }
}




















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




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack