Home  |  Delphi .net Home  |  System.Collections.BitArray  |  CopyTo Method
  
CopyTo  
Method  
Copies elements from the BitArray to a single dimension array
BitArray Class
System.Collections NameSpace
CF1.  Procedure CopyTo ( TargetArray : System.Array; TargetIndex : Integer ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
The CopyTo method takes elements from the current BitArray and overlays these values onto elements of the TargetArray.
 
The overlay starts at the beginning of the TargetArray unless the optional TargetIndex value is provided.
 
Important : the TargetArray must be created in advance - the CopyTo method overlays - it does not build. Also, the target array must have at least the same capacity as the number of elements being overlaid (copied).
 
Important : the TargetArray data type must be able to accomodate boolean types in the copy process. If the CopyTo method cannot cast to the target array, then an exception is thrown.
Notes
BitArrays and Arrays are 0 index based.
Microsoft MSDN Links
System.Collections
System.Collections.BitArray
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
Copying the whole BitArray onto the middle of an Array
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  MyList  : System.Collections.BitArray;
  MyArray : System.Array;
  i       : Integer;

begin
  // Create our array list object
  MyList := BitArray.Create(2);

  // Fill it
  MyList[0] := false;  // 0
  MyList[1] := false;  // 0

  // Create the target array
  MyArray := System.Array.CreateInstance(TypeOf(Boolean), 6);

  // And fill it
  MyArray.SetValue(TObject(true), 0);;
  MyArray.SetValue(TObject(true), 1);;
  MyArray.SetValue(TObject(true), 2);;
  MyArray.SetValue(TObject(true), 3);;
  MyArray.SetValue(TObject(true), 4);;
  MyArray.SetValue(TObject(true), 5);;

  // Copy to the middle of the target array
  Console.WriteLine('Copying to the middle ');
  Console.WriteLine('of the target array :');
  Console.WriteLine;

  MyList.CopyTo(MyArray, 2);

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

  Console.Readline;
end.
   Copying to the middle
   of the target array :
  
   True
   True
   False
   False
   True
   TRue
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author