Home  |  Delphi .net Home  |  System.Array  |  CopyTo Method
CopyTo  
Method  
Copies the current single dimension array values into another array
Array Class
System NameSpace
CF1.  Procedure CopyTo ( TargetArray:System.ArrayTargetArray : System.Array; TargetIndex : Integer ; ) ;
NotCF2.  Procedure CopyTo ( TargetArray:System.ArrayTargetArray : System.Array; TargetIndex : Int64; ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
Copies all of the elements of the current single dimension array into the TargetArray array at starting index TargetIndex.
Microsoft MSDN Links
System
System.Array
 
 
Copying a 3 element array into the middle of a 7 element array
program Project1;
{$APPTYPE CONSOLE}

var
  array1, array2 : System.Array;
  i              : Integer;

begin
  // Create two single dimension arrays of strings
  array1 := System.Array.CreateInstance(TypeOf(String), 3);
  array2 := System.Array.CreateInstance(TypeOf(String), 7);

  // Fill the first array with values
  array1.SetValue('Hello', 0);
  array1.SetValue('sad', 1);
  array1.SetValue('World', 2);

  // Copy the first array contents to the middle of the second array
  array1.CopyTo(array2, 2);

  // Display both arrays
  for i := 0 to array1.Length-1 do
    Console.WriteLine('array1[{0}]    = {1}',
                       i.ToString, array1.GetValue(i));

  Console.WriteLine;

  for i := 0 to array2.Length-1 do
    Console.WriteLine('array2[{0}] = {1}',
                       i.ToString, array2.GetValue(i));

  Console.ReadLine;
end.
Show full unit code
  array1[0]    = Hello
  array1[1]    = sad
  array1[2]    = World
  
  array2[0] =
  array2[1] =
  array2[2] = Hello
  array2[3] = sad
  array2[4] = World
  array2[5] =
  array2[6] =
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author