Home  |  Delphi .net Home  |  System.Collections.Queue  |  ToArray Method
ToArray  
Method  
Copies elements from the Queue to a new single dimension array
Queue Class
System.Collections NameSpace
CF1.  Function ToArray ( ) : System.Array;
CF : Methods with this mark are Compact Framework Compatible
Description
The ToArray method builds a new Array, and fills it with all the element values from the current Queue.
 
Just like CopyTo, ToArray performs a shallow copy. When the current Queue holds reference (non primitive) data types, the target array element values still refer to the same objects that current queue elements refer to. This is what is referred to as a shallow copy. A deep copy would create new versions of the referred objects.
Microsoft MSDN Links
System.Collections
System.Collections.Queue
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  MyQueue : System.Collections.Queue;
  MyArray : System.Array;
  i       : Integer;

begin
  // Create our queue
  MyQueue := Queue.Create;

  // Fill it
  MyQueue.EnQueue('Data');
  MyQueue.EnQueue('from');
  MyQueue.EnQueue('a');
  MyQueue.EnQueue('Queue');

  // Copy to the array
  MyArray := MyQueue.ToArray;

  // Display the array contents
  for i := 0 to MyArray.Length-1 do
    Console.WriteLine(MyArray.GetValue(i).ToString);

  Console.Readline;
end.
Show full unit code
  Data
  from
  a
  Queue
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author