数组和集合 / 字典

uses System.Generics.Collections;

var
  D1D2TDictionary<Integerstring>;
  Pair: TPair<Integer, string>;
begin
  D1 := TDictionary<Integer, string>.Create;
  D1.Add(1'one');
  D1.Add(2'two');
  D1.Add(3'tree');

  //the constructor copies all pairs
  D2 := TDictionary<Integer,
    string>.Create(D1);
  D2[3] := 'three';

  for Pair in D1 do
    WriteLn('d1: ', Pair.Keyis ',
      Pair.Value);
  //d1: 1 is one, 2 is two, 3 is tree

  for Pair in D2 do
    WriteLn('d2: ', Pair.Keyis ',
      Pair.Value);
  //d2: 1 is one, 2 is two, 3 is three
end.