Home  |  Delphi .net Home  |  System.Collections.Stack  |  ToArray Method
  
ToArray  
Method  
Copies elements from the Stack to a new single dimension array
Stack 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 Stack.
 
Just like CopyTo, ToArray performs a shallow copy. When the current Stack holds reference (non primitive) data types, the target array element values still refer to the same objects that current stack 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.Stack
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  MyStack : System.Collections.Stack;
  MyArray : System.Array;
  i       : Integer;

begin
  // Create our Stack
  MyStack := Stack.Create;

  // Fill it
  MyStack.Push('First');
  MyStack.Push('Second');
  MyStack.Push('Third');
  MyStack.Push('Fourth');

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

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

  Console.Readline;
end.
   Fourth
   Third
   Second
   First
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author