+ 1

Prefix and Postfix

When looking at Postfix Int x = 3; Int y = x++; Console.WriteLine(x+(“ “)+y); // x output is 4, y output is 3 But how come (int y) doesn’t also get a +1 since we did y = x++, because if the variable y equals x++ shouldn’t it also be 4?

9th Oct 2020, 12:56 AM
Dr.Tevvy Beats
Dr.Tevvy Beats - avatar
1 Odpowiedź
+ 3
If you assign x++ to y, you are assigning the original value of x rather than x+1. But if you assign ++x, you are assigning x+1. Of course eventually the x is increased by 1.
9th Oct 2020, 1:06 AM
你知道規則,我也是
你知道規則,我也是 - avatar