|
|
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['Name'] := 'Neil Moffatt';
MyTable['Manager'] := 'Steven Hemingway';
MyTable['Mentor'] := 'Danny Thorpe';
// Display the table contents
Console.WriteLine('MyTable at the start :');
Console.WriteLine;
Enumerator := MyTable.GetEnumerator;
while Enumerator.MoveNext do
begin
// Note that entries are returned in key sorted order
DictEntry := DictionaryEntry(Enumerator.Current);
Console.WriteLine('{0} = {1}',
DictEntry.Key.ToString,
DictEntry.Value.ToString);
end;
Console.WriteLine;
if MyTable.ContainsValue('Steven Hemingway')
then Console.WriteLine('''Steven Hemingway'' value found')
else Console.WriteLine('''Steven Hemingway'' value not found');
if MyTable.ContainsValue('Born Borg')
then Console.WriteLine('''Born Borg'' value found')
else Console.WriteLine('''Born Borg'' value not found');
Console.Readline;
end.
| Show full unit code | MyTable at the start :
Manager = Steven Hemingway
Name = Neil Moffatt
Mentor = Danny Thorpe
'Steven Hemingway' value found
'Born Borg' value not found
|
|
|
|