Difference of Unary operators ( += , =+ , ++x , x++ )

前端 未结 3 781
青春惊慌失措
青春惊慌失措 2021-01-14 04:56

What is the difference between these unary operators in C# ? . Can you provide me with example?

Please provide the name of each. :)

+= vs =+

++x vs

3条回答
  •  迷失自我
    2021-01-14 05:27

    Let's visualize the first ones, += and =+.

    Because "+" is action, "=" is assignment, so

    += is to add BEFORE assignment

    =+ is a bit confusing with "+", it could be "-", for example a=+7 or a=-7, anyway, it's a direct assignment.

    Similarly,

    ++x is "increment then return"

    x++ is "return then increase"

提交回复
热议问题