class IncrementExampleThe result is
{
public static void Main()
{
int x = 1;
Console.WriteLine("{0}, {1}", x++, x++);
Console.WriteLine("{0}, {1}", ++x, ++x);
}
}
1, 2
4, 5
Since x++ has a postfix operator, that means x will give its value to Console.WriteLine first, then perform the ++ operation. In contrast, prefix operator will perform ++ operation first, then give the value to Console.WriteLine.
No comments:
Post a Comment