else or return?

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

    I think it does not matter. You should go for readability and I think the less brackets the better. So I would return without the last 2 brackets (see sample below). Please do not think about performance when writing something like this it won't give you anything but too much complexity at an too early stage.

    if(result)
    {
      process 1
      return;
    }
    
    process 2
    

提交回复
热议问题