我有四个整数变量,分别名为C,S,F和U,每个变量根据文件例程的结果获得赋值,它们代表Checked,S uccessful,F ailed和UserDefined。 找出哪个变量具有最大值的最佳方法是什么?
尝试这样的事情:
var
C, S, F, U: Integer;
function WhichIsHighest(const Values: array of Integer): Integer;
var
I, Highest: Integer;
begin
Result := Low(Values);
Highest := Values[Result];
for I := Result+1 to High(Values) do begin
if Values[I] > Highest then begin
Result := I;
Highest := Values[I];
end;
end;
begin
... set C, S, F, U as needed ...
case WhichIsHighest([C, S, F, U]) of
0: ...; // C is highest
1: ...; // S is highest
2: ...; // F is highest
3: ...; // U is highest
end;
end;