-
-
Notifications
You must be signed in to change notification settings - Fork 3
System.Generics.Dictionary (en)
Alex edited this page Nov 14, 2019
·
1 revision
Represents a generic collection of key/value pairs.
IDictionary<TKey,TValue> = interface
TDictionary<TKey,TValue> = class(TInterfacedObject, IDictionary<TKey,TValue>)
The following code example creates an empty Dictionary<TKey,TValue> of strings, with string keys, and accesses it through the IDictionary<TKey,TValue> interface.
procedure UseDictionary;
var
dictionary: IDictionary<string, string>;
item: TPair<string, string>;
begin
Writeln('Print all environment variables...');
dictionary := System.Generics.Dictionary.TDictionary<string, string>.Create;
dictionary.Add('Key1', 'Value1');
dictionary.Add('Key2', 'Value2');
Writeln('Dictionary contains ' + dictionary.Count.ToString + ' elements');
if not dictionary.ContainsKey('Key1') then
raise Exception.Create('Dictionary not contain key1 item');
Writeln('Dictionary items:');
for item in dictionary do
Writeln(item.Key + ' = ' + item.Value);
end;