Home  |  Delphi .net Home  |  System.Collections.HashTable  |  GetEnumerator Method
GetEnumerator  
Method  
Gets an enumerator to allow reading the elements of the current HashTable
HashTable Class
System.Collections NameSpace
CF1.  Function GetEnumerator ( ) : IEnumerator;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns an IEnumerator object that allows the contents of the current HashTable to be read.
 
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.HashTable
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  MyTable    : System.Collections.HashTable;
  DictEntry  : DictionaryEntry;
  Enumerator : IEnumerator;

begin
  // Create our hash table
  MyTable := HashTable.Create;

  // Add entries to it
  MyTable['FirstName']  := 'Neil';
  MyTable['LastName']   := 'Moffatt';
  MyTable['Profession'] := 'Computer Programmer';
  MyTable['Age']        := TObject(47);
  MyTable['Birthday']   := DateTime.Create(1957, 2, 18);

  // Get an enumerator for the HashTable
  Enumerator := MyTable.GetEnumerator;

  // Display the array contents using the enumerator
  while Enumerator.MoveNext do
  begin
    DictEntry := DictionaryEntry(Enumerator.Current);
    Console.WriteLine('{0} = {1}',
                      DictEntry.Key.ToString,
                      DictEntry.Value.ToString);
  end;

  Console.Readline;
end.
Show full unit code
  FirstName = Neil
  Age = 47
  Bithday = 18/02/1957 00:00:00
  LastName = Moffatt
  Profession = Computer Programmer
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author