Home  |  Delphi .net Home  |  System.Array  |  Reverse Method
  
Reverse  
Method  
Reverses the sequence of elements in a single dimension array
Array Class
System NameSpace
NotCF1.  Procedure Reverse ( TheArray : System.Array ) ; Static;
CF2.  Procedure Reverse ( TheArray : System.Array; StartIndex : Integer; Count : Integer ) ; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
Reverses the sequence of elements in TheArray, a single dimension array.
 
If only a subset of the elements is to be reversed, then the optional StartIndex and Count parameters can specify a subset range.
Notes
Static methods are not methods of an object - they are simply class functions or procedures available at any time.
Microsoft MSDN Links
System
System.Array
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

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

var
  myArray : System.Array;
  i       : Integer;

begin
  // Create a 4 element single dimension array of strings
  myArray := System.Array.CreateInstance(TypeOf(String), 4);

  // Fill the array with values
  myArray.SetValue('---',       0);
  myArray.SetValue('  ---',     1);
  myArray.SetValue('    ---',   2);
  myArray.SetValue('      ---', 3);

  // Display the array contents
  for i := 0 to myArray.Length-1 do  // Arrays are always 0 based
    Console.WriteLine('myArray[{0}] = {1}',
                       i.ToString, myArray.GetValue(i));

  // Reverse the array order
  Console.WriteLine;
  Console.WriteLine('Reversing the array');
  Console.WriteLine;

  System.Array.Reverse(myArray);

  // Display the array contents
  for i := 0 to myArray.Length-1 do
    Console.WriteLine('myArray[{0}] = {1}',
                       i.ToString, myArray.GetValue(i));

  Console.ReadLine;
end.
   myArray[0] = ---
   myArray[1] =   ---
   myArray[2] =     ---
   myArray[3] =       ---
  
   Reversing the array
  
   myArray[0] =       ---
   myArray[1] =     ---
   myArray[2] =   ---
   myArray[3] = ---
Reversing just a subset of array elements
program Project1;
{$APPTYPE CONSOLE}

var
  myArray : System.Array;
  i       : Integer;

begin
  // Create a 4 element single dimension array of strings
  myArray := System.Array.CreateInstance(TypeOf(String), 5);

  // Fill the array with values
  myArray.SetValue('---',         0);
  myArray.SetValue('  ---',       1);
  myArray.SetValue('    ---',     2);
  myArray.SetValue('      ---',   3);
  myArray.SetValue('        ---', 4);

  // Display the array contents
  for i := 0 to myArray.Length-1 do  // Arrays are always 0 based
    Console.WriteLine('myArray[{0}] = {1}',
                       i.ToString, myArray.GetValue(i));

  // Reverse the array order
  Console.WriteLine;
  Console.WriteLine('Reversing the middle 3 elements');
  Console.WriteLine;

  System.Array.Reverse(myArray, 1, 3);

  // Display the array contents
  for i := 0 to myArray.Length-1 do
    Console.WriteLine('myArray[{0}] = {1}',
                       i.ToString, myArray.GetValue(i));

  Console.ReadLine;
end.
   myArray[0] = ---
   myArray[1] =   ---
   myArray[2] =     ---
   myArray[3] =       ---
   myArray[4] =         ---
  
   Reversing the middle 3 elements
  
   myArray[0] = ---
   myArray[1] =       ---
   myArray[2] =     ---
   myArray[3] =   ---
   myArray[4] =         ---
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author