小编mde*_*rie的帖子

关于 Delphi/Generic/array 的:为什么不能编译?

我想知道下面的通用代码有什么问题(用 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)

arrays delphi generics

3
推荐指数
1
解决办法
139
查看次数

标签 统计

arrays ×1

delphi ×1

generics ×1