Explicit or implicit execution control statement use

Posted by Andrei Rinea on Stack Overflow See other posts from Stack Overflow or by Andrei Rinea
Published on 2009-09-22T10:30:48Z Indexed on 2010/05/09 5:08 UTC
Read the original article Hit count: 193

Filed under:
|
|

I sometimes use

if (this._currentToolForeColor.HasValue)
    return this._currentToolForeColor.Value;
else
    throw new InvalidOperationException();

other times I use

if (this._currentToolForeColor.HasValue)
    return this._currentToolForeColor.Value;
throw new InvalidOperationException();

The two are equivalent, I know, but I am not sure which is the best and why.

This goes even further as you can use other execution-control statements such as brake or continue :

while(something)
{
    if(condition)
    {
        DoThis();
        continue;
    }
    else
        break;
}

versus

while(something)
{
    if(condition)
    {
        DoThis();
        continue;
    }
    break;
}

EDIT 1 : Yes the loop example(s) suck because they are synthetic (i.e.: made up for this question) unlike the first which is practical.

© Stack Overflow or respective owner

Related posts about c#

Related posts about preferences