Home  |  Delphi .net Home  |  System.Collections.ArrayList  |  Reverse Method
  
Reverse  
Method  
Reverse the sequence of elements in the ArrayList
ArrayList Class
System.Collections NameSpace
CF1.  Procedure Reverse ;
CF2.  Procedure Reverse ( StartIndex : Integer; Count : Integer ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
The Reverse method reverses the sequence of the elements in the ArrayList. All elements are reversed unless a range is specified via the StartIndex and Count parameters.
Microsoft MSDN Links
System.Collections
System.Collections.ArrayList
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
Reversing all elements in an array
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  List : System.Collections.ArrayList;
  i    : Integer;

begin
  // Create our array list object
  List := ArrayList.Create;

  // Fill it
  List.Add('0.');
  List.Add('1.-');
  List.Add('2.--');
  List.Add('3.---');

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

  // Reverse the order of the array
  Console.WriteLine;
  Console.WriteLine('Reversing the list order :');
  Console.WriteLine;
  List.Reverse;

  // Display List contents again
  for i := 0 to List.Count-1 do
    Console.WriteLine(List.Item[i]);

  Console.Readline;
end.
   0.
   1.-
   2.--
   3.---
  
   Reversing the list order :
  
   3.---
   2.--
   1.-
   0.
Reversing just a subset of array elements
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  List : System.Collections.ArrayList;
  i    : Integer;

begin
  // Create our array list object
  List := ArrayList.Create;

  // Fill it
  List.Add('0.');
  List.Add('1.-');
  List.Add('2.--');
  List.Add('3.---');

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

  // Reverse the middle 2 elements of the array
  Console.WriteLine;
  Console.WriteLine('Reversing the middle 2 elements :');
  Console.WriteLine;
  List.Reverse(1, 2);

  // Display List contents again
  for i := 0 to List.Count-1 do
    Console.WriteLine(List.Item[i]);

  Console.Readline;
end.
   0.
   1.-
   2.--
   3.---
  
   Reversing the middle 2 elements :
  
   0.
   2.--
   1.-
   3.---
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author