我想知道下面的通用代码有什么问题(用 Delphi 10.4.1 编写)。此外,还有其他方法可以实现相同的目标吗?我的意思是在数组中搜索(我知道我应该使用集合)。提前致谢 !
问候
type
TDelphiExtention = class
public
class function inside<T>(const value : T; const arr : array of T) : boolean;
end;
class function TDelphiExtention.inside<T>(const value : T; const arr : array of T) : boolean;
var
i : integer;
begin
result := true;
for i := Low(arr) to High(arr) do begin
if (arr[i] = value) then begin // E2015 Operator not applicable to this operand type !!!
exit;
end;
end;
result := false; // Not …Run Code Online (Sandbox Code Playgroud)