Comparison of programming languages (associative array): Difference between revisions

Content deleted Content added
Python: assume either Python 3 or some memory inefficiency
Delphi: Added example using generics.
Line 224:
 
===Delphi===
Versions of [[Borland Delphi|Delphi]] doesprior to 2009 do not offer direct support for associative arrays. However, you can simulate associative arrays using TStrings object. Here's an example:
 
<source lang="delphi">
Line 249:
DataField.Free;
end;
</source>
Delphi 2009 introduced support for generics as well as several standard generic containers, including TDictionary.
<source lang="delphi">
uses
SysUtils,
Generics.Collections;
 
var
PhoneBook: TDictionary<string, string>;
Entry: TPair<string, string>;
 
begin
PhoneBook := TDictionary<string, string>.Create;
PhoneBook.Add('Sally Smart', '555-9999');
PhoneBook.Add('John Doe', '555-1212');
PhoneBook.Add('J. Random Hacker', '553-1337');
 
for Entry in PhoneBook do
Writeln(Format('Number for %s: %s',[Entry.Key, Entry.Value]));
end.
</source>