我写了代码
procedure Pair;
var
PairList: TList<TPair<UInt32, UInt32>>;
LPair: TPair<UInt32, UInt32>;
begin
PairList := TList<TPair<UInt32, UInt32>>.Create;
try
PairList.Add(LPair.Create(4,10));
finally
PairList.Free;
end;
end;
Run Code Online (Sandbox Code Playgroud)
当我释放PairList时,我创建的Pair也需要被释放?
Dal*_*kar 10
您不必释放TPair变量,因为它是值类型 - 声明为的记录
TPair<TKey,TValue> = record
Key: TKey;
Value: TValue;
constructor Create(const AKey: TKey; const AValue: TValue);
end;
Run Code Online (Sandbox Code Playgroud)
如果您尝试释放它将LPair.Free导致编译器错误
E2003未声明的标识符:'免费'