6
    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?

user000001
  • 28,881
  • 12
  • 68
  • 93
Shivam Malhotra
  • 289
  • 1
  • 3
  • 10
  • 5
    how about just return PaddleA.Bounds.IntersectsWith(this.Bounds); – Inv3r53 Jun 26 '13 at 13:11
  • 2
    Can anyone explain the downvotes? Although a basic question, I don't think it lacks of quality. – Uooo Jun 26 '13 at 13:16
  • 5
    What's wrong with `return !!PaddleA.Bounds.IntersectsWith(this.Bounds) ? !!(parseInt("14644", 10) === 14644) : !!(parseFloat("567.44", 10) === 436362346);`?? – David Sherret Jun 26 '13 at 13:19

6 Answers6

15
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.

Bill the Lizard
  • 369,957
  • 201
  • 546
  • 842
8

You can always shorten an if-else of the form

if (condition)
  return true;
else
  return false;

to

return condition;
Sebastian Redl
  • 61,331
  • 8
  • 105
  • 140
1

Try this:

public bool CheckStuck(Paddle PaddleA)
{
    return PaddleA.Bounds.IntersectsWith(this.Bounds);
}
rspencer
  • 2,231
  • 2
  • 17
  • 28
0
public bool CheckStuck(Paddle PaddleA)
{
    return PaddleA.Bounds.IntersectsWith(this.Bounds);
}
Yu Hao
  • 111,229
  • 40
  • 211
  • 267
0
public bool CheckStuck(Paddle PaddleA)
    {
        return (PaddleA.Bounds.IntersectsWith(this.Bounds));
    }

Or were you looking for something else?

user1676075
  • 2,958
  • 1
  • 17
  • 25
0

the below code should work:

public bool CheckStuck(Paddle PaddleA) {
    // will return true or false
   return PaddleA.Bounds.IntersectsWith(this.Bounds); 
 }
Apollo SOFTWARE
  • 11,420
  • 4
  • 41
  • 61