Idon'tunderstandhow'i'become4
c#
how does the optput come as
3
3
4
I don't understand how 'i' become 4 for last
code:
int i = 2;
Console.WriteLine(++i);
Console.WriteLine(i++);
Console.WriteLine(i);
回答
Because you first used the prefix increment operator and then used postfix.
int i = 2;
Console.WriteLine(++i); // i became 3 *before it was used*
Console.WriteLine(i++); // i first used, still 3, and then incremented becoming 4
Console.WriteLine(i); // i is still 4