i++ :- In this scenario first the value is assigned and then increment happens. In the below code snippet first the value of “i” is assigned to “j” and then “i” is incremented.
++i :- In this scenario first the increment is done and then value is assigned. In the below code snippet value of “j” is 2 and value of “i” is also 2.
Below are some sample code where postfix and prefix fits in.
while (i < 5) //evaluates conditional statement
++i; //increments i
while (i++ < 5) //evaluates conditional statement with i value before increment
int i = 0;
int MyArray = new int;
MyArray[i++] = 1234; //sets array at index 0 to ‘1234’ and i is incremented
MyArray[i] = 5678; //sets array at index 1 to ‘5678’
int temp = MyArray[–i]; //temp is 1234
Also see the following c# interview questions video on i++ vs ++i (postfix and prefix).