else or return?

后端 未结 19 894
故里飘歌
故里飘歌 2021-01-01 13:27

Which one out of following two is best wrt to performance and standard practice. How does .NET internally handles these two code snippets?

Code1

If(r         


        
19条回答
  •  无人及你
    2021-01-01 13:53

    If there is common code, that needs to be executed after the if/else block, then option 1.

    If the if-else block is the last thing to do in a function, then option 2.

    Personally I always use option 1. If there is a return stateent, it comes after the else block

提交回复
热议问题