Queue.CopyTo Method


Queue.CopyTo Method

Class

System.Collections.Queue (standard version)

System.Collections.Generic.Queue (generic version)

Syntax

     queueVariable.CopyTo(array, index) 


array (required; compatible array)

Array to which to copy the queue's objects


index (required; Integer)

The index of the first zero-based array element to receive a queue member

Description

The CopyTo method copies the queue elements into an existing array, starting at a specified array index.

Usage at a Glance

  • The array can be of any data type that is compatible with the queue elements. An array of Integer can accept Short queue elements but not String elements.

  • The array must be sized to accommodate the elements of the queue prior to calling the CopyTo method.

Example

The sample code copies queue items to an array.

     Dim nameQueue As New Queue     Dim nameArray(  ) As Object     ' ----- Build the queue.     nameQueue.Enqueue("Chopin")     nameQueue.Enqueue("Mozart")     nameQueue.Enqueue("Beethoven")     ' ----- Size the array and copy elements.     ReDim nameArray(nameQueue.Count - 1)     nameQueue.CopyTo(nameArray, 0) 

Version Differences

Visual Basic 2005 adds support for generics to queues, as discussed in Chapter 10.

See Also

Queue Class, Queue.ToArray Method




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net