c# - else or return? -


Which of the following two is best for performance and standard practice. How does .NET internal handle these two code snippets?

Code1

  if (the result) {process1 (); } And {process2 (); }  

or code 2

  if (the result) {process1 (); Return; } Process2 ();  

Performance difference, if any, is negligible in any normal case.

A standard practice (among the other) is to try to keep a single exit point from one method so that the first option can negotiate in favor of.

The actual execution for return is likely to jump till the end of the method, where the code is the code to wrap the stack frame, it is possible that the final execution The appropriate code is the same for two codes.


Comments