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 virtual void CopyTo(
Array array,
int index
)
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.index
- The zero-based index in array at which copying begins.
Returns
Queue.CopyTo
method returns
Example
The following example shows how to copy a Queue into a one-dimensional array.
//from w w w. ja v a 2 s .c om
using System;
using System.Collections;
public class SamplesQueue {
public static void Main() {
Queue mySourceQ = new Queue();
mySourceQ.Enqueue( "A" );
mySourceQ.Enqueue( "B" );
mySourceQ.Enqueue( "C" );
mySourceQ.Enqueue( "D" );
mySourceQ.Enqueue( "E" );
mySourceQ.Enqueue( "F" );
Array myTargetArray=Array.CreateInstance( typeof(String), 15 );
mySourceQ.CopyTo( myTargetArray, 6 );
}
}
The code above generates the following result.