In C# what is the difference between myInt++ and ++myInt?

后端 未结 11 1813
我寻月下人不归
我寻月下人不归 2020-12-06 03:11

I\'m having a hard time understanding what the difference is between incrementing a variable in C# this way:

myInt++;

and

         


        
11条回答
  •  無奈伤痛
    2020-12-06 03:34

    The pre-fix operator ++myInt is a way of reducing lines: increment the variable before passing it to someplace else. It's also a nice way to reduce readability, since it's uncommon.

    MyMethod(++myInt); 
    

    vs.

    myInt++; 
    MyMethod(myInt);
    

    To me the second is a lot easier to read.

提交回复
热议问题