Is there any performance difference with ++i vs i += 1 in C#?

后端 未结 5 655
半阙折子戏
半阙折子戏 2021-01-19 12:42

i += a should be equivalent to i = i + a. In the case where a == 1, this is supposedly less efficient as ++i as it involves more accesses to memory; or will the compiler mak

5条回答
  •  野的像风
    2021-01-19 13:12

    The compiler should optimise the code whichever way you write it so I believe i = i + 1 is the same as ++i.

提交回复
热议问题