数组和集合 / 字典

uses System.Generics.Collections;

var
  D1D2, DAll: TDictionary<Integerstring>;
  Pair: TPair<Integer, string>;
begin
  D1 := TDictionary<Integer, string>.Create;
  D1.Add(1'one');

  D2 := TDictionary<Integer, string>.Create;
  D2.Add(2'two');
  D2.Add(3'three');

  //copy of the first, then merge
  DAll :=
    TDictionary<Integer, string>.Create(D1);
  for Pair in D2 do
    DAll.AddOrSetValue(Pair.Key, Pair.Value);
  //dAll is {1: one, 2: two, 3: three}

  WriteLn('count is ', DAll.Count);
  WriteLn('dAll[3] is ', DAll[3]);
end.