C # unary operator precedence and unexpected result

I just started with C #. I read about operator precedence, and there was a part about unary operator precedence. I tried to imagine a situation where I can see things like this. And for example:

int a = 5;
a = -a++;

      

An example is silly, but still ... "Unars" are right-associative. I expected a result of -6, but it is -5. I understand that "++" is returned first and then incremented. But WHAT does it increase if not "a"? Why is "a" not affected?

Thank you =]

+3


source to share





All Articles