A B C
示例一:
if(A is not blank){
if(B is not blank){
if(C is not blank){
code.....
} else{
return "C can not be blank";
}
} else{
return "B can not be blank";
}
}else{
return "A can not be blank";
}
示例二:
if(A is blank){
return "A can not be blank";
}
if(B is blank){
return "B can not be blank";
}
if(C is blank){
return "C can not be blank";
}
code...
------解决思路----------------------
有区别吗? 不知道
我一般用第二种写法
------解决思路----------------------
非要这样判断的话,建议第二种
看着舒服写,而且每次判断直接return,阅读起来比较方便
第一种如果有4 层以上的判断,还得数着到哪一个else了
------解决思路----------------------
一般都会用第二种吧,简洁清晰
------解决思路----------------------
第二种写法把第一种可读性强一些,第一种看起来比较乱
------解决思路----------------------
第二种写法比第一种可读性强一些,第一种看起来比较乱
------解决思路----------------------
两种写法在逻辑上显然是有区别的。
------解决思路----------------------
当中那段code如果很长(超过一个屏幕)的话,
显然是第二种好些,一目了然。
第一种的话,那段code看完,谁还记得前面判空的顺序啊。
如果中间那段code只有一两行的话,就无所谓了。
------解决思路----------------------
主要看ABC之间有没有关系来选择那种
------解决思路----------------------
if(A is blank){
return "A can not be blank";
} else if(B is blank){
return "B can not be blank";
} else if(C is blank){
return "C can not be blank";
} else {
code...
}
这样写可能能让楼主更舒服一些
------解决思路----------------------
PS:第一种在某种意义上代码快些。
------解决思路----------------------
没区别,看自己习惯
------解决思路----------------------
必须2,1导致代码圈复杂度提升,如果公司要求严格些,直接不合格。
------解决思路----------------------
最好不要用嵌套,嵌套3层或以上就很难读
------解决思路----------------------
A\B\C三者为空、不为空,会不会影响相互的关系以及运算?
无关的话就第二种,有关的话还不得不第一种
------解决思路----------------------
我一般也是用
if()
else if()
这种写法 嵌套就别弄了
------解决思路----------------------
if(a is blank
------解决思路----------------------
b is blank
------解决思路----------------------
c is blank)
{
a ,b,c can not be blank
}
------解决思路----------------------
#define MSGREMAN(Condition) \
MSG(Condition. Condition##can not be blank, __VA_ARGS__)
CString MSG(bool bCondition,CString strMsg)
{
return bCondition?“”: strMsg;
}
------解决思路----------------------

java 啊,还以为c++
------解决思路----------------------
就你这个情况来说 第二种的效率比if else的还高
第一种可以用if else来代替
if if 这2种情况的使用场景不太一样
------解决思路----------------------
try{
a.toString();
b.toString();
c.toString();
} catch(NullPointException e) {
System.out.println("fucking null!");
}
