else or return?

后端 未结 19 895
故里飘歌
故里飘歌 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:45

    Here's some additional reading on the guard clause: http://www.c2.com/cgi/wiki?GuardClause

    One term I did not see mentioned that I think is important -- the purpose of the guard clause is to increase readability. Single exit methods can tend toward "arrow" code (where nesting of statements makes an arrowhead).

提交回复
热议问题