0

I was writing an app, and for this piece of code(in the end of a method)

if (selectSdfDialog.ShowDialog() == DialogResult.OK)
{
    Sdf = selectSdfDialog.FileName;
    var regex = new Regex("[VQ]\\d{11}");
    Serial = regex.Match(selectSdfDialog.SafeFileName).ToString();
}

Resharper gave me a hint to invert the if statement, bringing it to this

if (selectSdfDialog.ShowDialog() != DialogResult.OK) return;
Sdf = selectSdfDialog.FileName;
var regex = new Regex("[VQ]\\d{11}");
Serial = regex.Match(selectSdfDialog.SafeFileName).ToString();

My question is, is this working faster or somehow better, and if yes, what is the difference for the compiler?

vcmkrtchyan
  • 2,536
  • 5
  • 30
  • 59
  • it the same and resharper again can give you hint - invert this statement – Grundy Jul 08 '15 at 15:21
  • 2
    It reduces the indentation. Can sometimes make the code more readable IMO. – M4N Jul 08 '15 at 15:21
  • @Grundy in that case it's a just a possible command for resharper, but before this it was showing this hint with a yellow(maybe warning) sign – vcmkrtchyan Jul 08 '15 at 15:26

1 Answers1

1

It's not a compiler optimization, it's an author optimization. It flattens arrow code.

zzzzBov
  • 174,988
  • 54
  • 320
  • 367
  • 3
    I like the last sentence: _"But whatever you do, you have to abandon the ill-conceived idea that there should only be one exit point at the bottom of the function."_ – Tim Schmelter Jul 08 '15 at 15:28