Prefix increment and postfix increment operators in C#

using System;
 
public class IncrementClass
{
   public static void Main( string[] args )
   {
      int c;
 
      // demonstrate postfix increment operator
      c = 5; // assign 5 to c
      Console.WriteLine( c ); // display 5
      Console.WriteLine( c++ ); // display 5 again, then increment
      Console.WriteLine( c ); // display 6
 
      Console.WriteLine(); // skip a line
 
      // demonstrate prefix increment operator
      c = 5; // assign 5 to c
      Console.WriteLine( c ); // display 5
      Console.WriteLine( ++c ); // increment then display 6
      Console.WriteLine( c ); // display 6 again
   } // end Main
} // end class IncrementClass

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.