I am using ReSharper to refactor my code, and one of the suggestions of ReSharper is to use a respective branch instead a if statement that is always true.
If I have
if (myVar != null){
//code
}
And I apply the respective branch the code is like the following
{
//code
}
Is this a short cut of an if statement? What is this used for? What is the difference between the cutely brackets and nothing?
Thanks in advance.
The block is required to stay there, or semantics would change.
The scope of variables declared inside the branch block would change when you remove the braces. Potentially with conflicting/hiding (lambda) variables this would lead to surprises.
To remove the braces, position the cursor on either one and hit Alt-Enter, 'Remove Braces'
Reintroduce braces: select block of code, Ctrl-Alt-J, 7
to surround with block :)
In ReSharper 6.0 this command also removes braces if you don't have variable declarations inside.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With