C# Queue ToArray
Description
Queue ToArray
copies the Queue elements to a new array.
Syntax
Queue.ToArray
has the following syntax.
public virtual Object[] ToArray()
Returns
Queue.ToArray
method returns
Example
The following example shows how to copy a Queue into a one-dimensional array.
//from www . jav a2 s.c o m
using System;
using System.Collections;
public class SamplesQueue {
public static void Main() {
Queue mySourceQ = new Queue();
mySourceQ.Enqueue( "1" );
mySourceQ.Enqueue( "2" );
mySourceQ.Enqueue( "3" );
Array myTargetArray=Array.CreateInstance( typeof(String), 15 );
mySourceQ.CopyTo( myTargetArray, 6 );
Object[] myStandardArray = mySourceQ.ToArray();
}
}
The code above generates the following result.