我希望在Delphi项目中使用 TDictionary
。但是我遇到了一个问题,如何创建一个默认值的常量数组TDictionary
?
例如,我想为字典分配4个项目,如下所示的代码(用于TItem
的常量数组):
...
type
TItem = record
_Key: string;
_Value: string;
end;
var
Dic: array [0..3]of TItem=(
(_Key:'A' ; _Value:'Apple'),
(_Key:'B' ; _Value:'Book'),
(_Key:'C' ; _Value:'C++'),
(_Key:'D' ; _Value:'Delphi')
);
...
有没有使用 TDictionary
完成这项工作的方法?
我想创建一个常量数组,其结构类似于下面的 Dic
。
...
var
Dic: TDictionary<string, string>;
begin
Dic := TDictionary<string, string>.Create;
try
Dic.Add('A', 'Apple');
Dic.Add('B', 'Book');
Dic.Add('C', 'C++');
Dic.Add('D', 'Delphi');
finally
///
end;
...
有没有人能给我一些建议?(如果我的英语不好,请原谅!)
for value in array
循环,而不是for integer from magic-index to function(some-array)
。只是为了使它更加健壮。 - Arioch 'The