Pre And Post Increment : Prefix Postfix Operator « Operator « C# / CSharp Tutorial






using System;

class MainClass
{
   static void Main()
   {
      int x = 5, y;
      y = x++;                        
      Console.WriteLine("y: {0}, x: {1}", y, x);

      x = 5;
      y = ++x;                        
      Console.WriteLine("y: {0}, x: {1}", y, x);

      x = 5;
      y = x--;                        
      Console.WriteLine("y: {0}, x: {1}", y, x);

      x = 5;
      y = --x;                        
      Console.WriteLine("y: {0}, x: {1}", y, x);
   }
}
y: 5, x: 6
y: 6, x: 6
y: 5, x: 4
y: 4, x: 4








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 ++