如何简化返回true或false的IF语句? [英] How do I simplify an IF statement that returns true or false?
本文介绍了如何简化返回true或false的IF语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public bool CheckStuck(Paddle PaddleA)
{
if (PaddleA.Bounds.IntersectsWith(this.Bounds))
return true;
else
return false;
}
我觉得上面的代码,在程序中,有点多余,想知道是否有办法将其缩短为一个表达式。很抱歉,如果我遗漏了一些明显的东西。
I feel like the above code, within the procedure, is a bit redundant and was wondering if there was a way to shorten it into one expression. Sorry if I'm missing something obvious.
目前,如果该陈述为真,则返回true,同样为false。
At the moment if the statement is true, it returns true and the same for false.
那么,有没有办法缩短它?
So, is there a way to shorten it?
推荐答案
public bool CheckStuck(Paddle PaddleA)
{
return PaddleA.Bounds.IntersectsWith(this.Bounds)
}
返回
后的条件评估为 True
或错误
,所以不需要if / else。
The condition after return
evaluates to either True
or False
, so there's no need for the if/else.
这篇关于如何简化返回true或false的IF语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文