Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I simplify an IF statement that returns true or false?

Tags:

if-statement

    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.

At the moment if the statement is true, it returns true and the same for false.

So, is there a way to shorten it?

like image 293
Shivam Malhotra Avatar asked Jun 26 '13 13:06

Shivam Malhotra


1 Answers

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

The condition after return evaluates to either True or False, so there's no need for the if/else.

like image 177
Bill the Lizard Avatar answered Oct 16 '22 07:10

Bill the Lizard