我已经在Delphi中编程了一段时间,但我从未遇到过我在SO上的问题中找到的语法.有这样的语法:
var Dic: TDictionary<Integer,string>;
Run Code Online (Sandbox Code Playgroud)
我从未见过<type, type>.这是什么意思?何时何地可以使用?我找不到任何东西,因为谷歌省略了像"<",">"这样的字符.
在许多语言中,它通常是映射或模板实例化,Delphi称这些泛型,并且可以在此处看到声明它们的示例:
type
TPair<Tkey,TValue> = class // TKey and TValue are type parameters
FKey: TKey;
FValue: TValue;
function GetValue: TValue;
end;
function TPair<TKey,TValue>.GetValue: TValue;
begin
Result := FValue;
end;
Run Code Online (Sandbox Code Playgroud)
您的特定示例定义的是将整数映射到字符串的字典.