首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

Generics.Collections TDictionary,该怎么解决

2012-04-17 
Generics.Collections TDictionaryDelphi Generics.Collections单元中TDictionaryTKey,TValue class(T

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(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; 

热点排行