I recall reading somewhere that for a variable int i
both ++i and i++ generate a temporary in C#. Does anyone know why that is the case? Is their performance identical?
UPDATE
So from Eric Lippert's answer in the duplicate, the steps for pre-increment are as follows:
For pre-increment
1) x is evaluated to produce the variable
2) the value of the variable is copied to a temporary location
3) the temporary value is incremented to produce a new value (not overwriting the temporary!)
4) the new value is stored in the variable
5) the result of the operation is the new value
Why is step 2 necessary? Why not increment the variable in place?