Home  |  Delphi .net Home  |  System.Collections.HashTable  |  Add Method
  
Add  
Method  
Add an entry to the current HashTable
HashTable Class
System.Collections NameSpace
CF1.  Procedure Add ( Key : Object; Value : Object ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
Add a Key-Value data pair to the current HashTable.
 
There are two other ways (shown in the example) of adding to the table :
 
Table.Item[Key] := Value
 
Table[Key] := Value
 
The latter is an abbreviated version of the former, allowed since Item is the main (indexed) property of HashTable.
Notes
Value may be null.
Microsoft MSDN Links
System.Collections
System.Collections.HashTable
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
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 using 3 different but equivalent ways
  MyTable['FirstName']     := 'Neil';
  MyTable.Item['LastName'] := 'Moffatt';
  MyTable.Add('Profession', 'Computer Programmer');

  // Add some other data types
  MyTable.Add('Age', TObject(47));
  MyTable.Add('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.
   FirstName = Neil
   Age = 47
   Bithday = 18/02/1957 00:00:00
   LastName = Moffatt
   Profession = Computer Programmer
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author