If statement 如何简化返回true或false的IF语句?

If statement 如何简化返回true或false的IF语句?,if-statement,If Statement,我觉得上面的代码在过程中有点多余,我想知道是否有办法将其缩短为一个表达式。对不起,我遗漏了一些明显的东西 此时,如果语句为true,则返回true,false返回相同的结果 那么,有没有办法缩短它 public bool CheckStuck(Paddle PaddleA) { if (PaddleA.Bounds.IntersectsWith(this.Bounds)) return true; else

我觉得上面的代码在过程中有点多余,我想知道是否有办法将其缩短为一个表达式。对不起,我遗漏了一些明显的东西

此时,如果语句为true,则返回true,false返回相同的结果

那么,有没有办法缩短它

    public bool CheckStuck(Paddle PaddleA)
    {
        if (PaddleA.Bounds.IntersectsWith(this.Bounds))
            return true;
        else
            return false;
    }

return
之后的条件的计算结果为
True
False
,因此不需要if/else。

始终可以缩短表单的if-else

public bool CheckStuck(Paddle PaddleA)
{
    return PaddleA.Bounds.IntersectsWith(this.Bounds)
}

试试这个:

return condition;
public bool CheckStuck(Paddle PaddleA)
{
    return PaddleA.Bounds.IntersectsWith(this.Bounds);
}

或者您正在寻找其他内容?

以下代码应该可以工作:

public bool CheckStuck(Paddle PaddleA)
    {
        return (PaddleA.Bounds.IntersectsWith(this.Bounds));
    }

返回pallea.Bounds.IntersectsWith(this.Bounds)怎么样;有人能解释为什么会有人投反对票吗?虽然这是一个基本问题,但我不认为它缺乏质量。
return有什么问题!!划桨。边界。与(此。边界)相交!!(parseInt(“14644”,10)==14644):!!(567.44,10)=436362346 ;?谢谢!真不敢相信我居然没想到。
public bool CheckStuck(Paddle PaddleA)
{
    return PaddleA.Bounds.IntersectsWith(this.Bounds);
}
public bool CheckStuck(Paddle PaddleA)
    {
        return (PaddleA.Bounds.IntersectsWith(this.Bounds));
    }
public bool CheckStuck(Paddle PaddleA) {
    // will return true or false
   return PaddleA.Bounds.IntersectsWith(this.Bounds); 
 }