int x = 10; x += x–; in .Net – Why?

Look at this statement:

x += x--;

This is equivalent to:

x = x + x--;

Which is equivalent to:

int a1 = x; // a1 = 10, x = 10
int a2 = x--; // a2 = 10, x = 9
x = a1 + a2; // x = 20

So x is 20 afterwards – and that’s guaranteed by the spec.

What’s also pretty much guaranteed, although not by the spec, is that anyone using such code will be attacked by their colleagues. Yes, it’s good that the result is predictable. No, it’s not good to use that kind of code.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)