The difference between prefix and postfix forms of ++ : Prefix Postfix Operator « Operator « C# / CSharp Tutorial






using System; 
 
class Example {  
  public static void Main() {    
    int x, y; 
    int i; 
 
    x = 1; 
    Console.WriteLine("Series generated using y = x + x++;"); 
    for(i = 0; i < 10; i++) { 
      y = x + x++; // postfix ++ 
      Console.WriteLine(y + " "); 
    } 
    Console.WriteLine(); 
 
    x = 1; 
    Console.WriteLine("Series generated using y = x + ++x;"); 
    for(i = 0; i < 10; i++) { 
      y = x + ++x; // prefix ++ 
      Console.WriteLine(y + " "); 
    } 
    Console.WriteLine(); 
    
  } 
}
Series generated using y = x + x++;
2
4
6
8
10
12
14
16
18
20

Series generated using y = x + ++x;
3
5
7
9
11
13
15
17
19
21








3.3.Prefix Postfix Operator
3.3.1.Increment and Decrement
3.3.2.Pre And Post Increment
3.3.3.The difference between prefix and postfix forms of ++
3.3.4.postfix increment
3.3.5.prefix increment
3.3.6.postfix decrement
3.3.7.prefix decrement
3.3.8.Using the Post-Increment Operator
3.3.9.Using the Pre-Increment Operator
3.3.10.Operators ++