Home  |  Delphi .net Home  |  System.Collections.ArrayList  |  AddRange Method
AddRange  
Method  
Add a range of elements to the end of the ArrayList
ArrayList Class
System.Collections NameSpace
CF1.  Procedure AddRange ( Collection : ICollection; ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
All of the elements of Collection are added to the end of the ArrayList.
 
The element Count is incremented by the count of elements added. Capacity is doubled if exceeded.
Microsoft MSDN Links
System.Collections
System.Collections.ArrayList
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  List1, List2 : System.Collections.ArrayList;
  i            : Integer;

begin
  // Create our array list objects
  List1 := ArrayList.Create;
  List2 := ArrayList.Create;

  // Fill them
  List1.Add('0.Zero');
  List1.Add('1.One');
  List1.Add('2.Two');
  List1.Add('3.Three');
  List1.Add('4.Four');

  List2.Add('A.Aadvark');
  List2.Add('B.Badger');
  List2.Add('C.Chervil');

  // Add the second list onto the end of the first
  Console.WriteLine('Adding List2 onto the end of List1 :');
  Console.WriteLine;
  List1.AddRange(List2);

  // Display List1 contents : note the 0 indexing
  for i := 0 to List1.Count-1 do
    Console.WriteLine(List1.Item[i]);

  Console.Readline;
end.
Show full unit code
  Adding List2 onto the end of List1 :
  
  0.Zero
  1.One
  2.Two
  3.Three
  4.Four
  A.Aadvark
  B.Badger
  C.Chervil
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author