Pre And Post Increment : Prefix Postfix Operator : Operator C# Examples


C# Examples » Operator » Prefix Postfix Operator »

 

Pre And Post Increment









    
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);
      }
}
    
   
  
   



Output

y: 5, x: 6
y: 6, x: 6
y: 5, x: 4
y: 4, x: 4


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Operator
» Prefix Postfix Operator