delphi case 语句解决方案
delphi case 语句
这样写的case可以嘛?
------解决方案--------------------
可以这样写,不过为了安全可以在加个else,没有必要用 break
case num of
1: fun1;
2: fun2;
else
other;
end;
------解决方案--------------------
------解决方案--------------------
if Gprs then
case meterNumber of
1,3,4,5:CombinCode:='39341';
2:CombinCode:='39351';
6,7:CombinCode:='39351';
else
CombinCode:='324324324';
end;
可以的,有必要就加一个else
------解决方案--------------------
为了程序更加健壮,建议增加ELSE分支。。。
------解决方案--------------------
如果你已经确定了你的返回值的范围了,这样写就没问题。这里是Pascal,不需要break
------解决方案--------------------
可以的,没问题
- Delphi(Pascal) code
if Gprs=true then begin case meterNumber of 1,3,4,5: begin CombinCode := '39341'; end; 2: begin CombinCode := '39351'; end; 6,7: begin CombinCode := '39351'; end; end; end;
这样写的case可以嘛?
------解决方案--------------------
可以这样写,不过为了安全可以在加个else,没有必要用 break
case num of
1: fun1;
2: fun2;
else
other;
end;
------解决方案--------------------
------解决方案--------------------
if Gprs then
case meterNumber of
1,3,4,5:CombinCode:='39341';
2:CombinCode:='39351';
6,7:CombinCode:='39351';
else
CombinCode:='324324324';
end;
可以的,有必要就加一个else
------解决方案--------------------
为了程序更加健壮,建议增加ELSE分支。。。
------解决方案--------------------
如果你已经确定了你的返回值的范围了,这样写就没问题。这里是Pascal,不需要break
------解决方案--------------------
可以的,没问题