Home  |  Delphi .net Home  |  System.Collections.ArrayList  |  GetEnumerator Method
GetEnumerator  
Method  
Gets an enumerator to allow reading the elements of the current ArrayList
ArrayList Class
System.Collections NameSpace
CF1.  Function GetEnumerator ( ) : IEnumerator ;
CF2.  Function GetEnumerator ( StartIndex:IntegerStartIndex : Integer; Count : Integer; ) : IEnumerator;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns an IEnumerator object that allows the contents of the current ArrayList to be read. Optionally, you may specify that the enumerator works with only Count elements from StartIndex.
 
A call to MoveNext must be performed before a value can be read from the enumerator - the starting position is before the first element.
References
IEnumerator
Microsoft MSDN Links
System.Collections
System.Collections.ArrayList
 
 
Geting all elements from an ArrayList
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  List       : System.Collections.ArrayList;
  Enumerator : IEnumerator;

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

  // Fill it
  List.Add('Hello');
  List.Add('from');
  List.Add('Delphi');
  List.Add('Basics');

  // Get the enumerator for the whole ArrayList
  Enumerator := List.GetEnumerator;

  // Display the array using the enumerator
  // Note : we must call MoveNext before we can see the 1st element
  while Enumerator.MoveNext do
    Console.WriteLine(Enumerator.Current.ToString);

  Console.Readline;
end.
Show full unit code
  Hello
  from
  Delphi
  Basics
Getting just a subset of ArrayList elements
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  List       : System.Collections.ArrayList;
  Enumerator : IEnumerator;

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

  // Fill it
  List.Add('Hello');
  List.Add('from');
  List.Add('Delphi');
  List.Add('Basics');

  // Get the enumerator for the just the middle 2 elements
  Enumerator := List.GetEnumerator(1, 2);

  // Display the array using the enumerator
  // Note : we must call MoveNext before we can see the 1st element
  while Enumerator.MoveNext do
    Console.WriteLine(Enumerator.Current.ToString);

  Console.Readline;
end.
Show full unit code
  from
  Delphi
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author