Generics.Collections TDictionary,该怎么解决
Generics.Collections TDictionary
Delphi Generics.Collections单元中
TDictionary<TKey,TValue> = class(TEnumerable<TPair<TKey,TValue>>)
private
type
TItem = record
HashCode: Integer;
Key: TKey;
Value: TValue;
end;
TItemArray = array of TItem;
如何改变 Dictionary中的key值?
------解决方案--------------------
Delphi Generics.Collections单元中
TDictionary<TKey,TValue> = class(TEnumerable<TPair<TKey,TValue>>)
private
type
TItem = record
HashCode: Integer;
Key: TKey;
Value: TValue;
end;
TItemArray = array of TItem;
如何改变 Dictionary中的key值?
------解决方案--------------------
- Delphi(Pascal) code
var a : TDictionary<integer,integer>; b : TPair<integer,integer>; begin a := TDictionary<integer,integer>.create; try a.Add(1, 1); b.Key := 1; b.Value := a.Items[b.Key]; a.Remove(b.Key); b.Key := 2; a.Add(b.Key, b.Value); Caption := IntToStr(a.Items[2]); finally a.Free; end;