Home  |  Delphi .net Home  |  System.Collections.ArrayList  |  InsertRange Method
InsertRange  
Method  
Add a range of elements into the ArrayList
ArrayList Class
System.Collections NameSpace
CF1.  Procedure InsertRange ( Index:IntegerIndex : Integer; Collection : ICollection; ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
All of the elements of Collection are inserted into the ArrayList at the given Index.
 
The element Count is incremented by the count of elements added. Capacity is doubled if exceeded.
Notes
An exception is raised if the Index value is outside of the range 0 .. Count. When set to Count, the collection is added to the end of the array.
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');

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

  // Add the second list into the middle of the first
  Console.WriteLine('Adding List2 at index 2 of List1 :');
  Console.WriteLine;
  List1.InsertRange(2, 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 at index 2 of List1 :
  
  0.Zero
  1.One
  A.Aadvark
  B.Badger
  C.Chervil
  2.Two
  3.Three
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author