C# Queue CopyTo
Description
Queue
copies the Queue
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);
}
}