Mega Code Archive

 
Categories / C# Tutorial / 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);    } } y: 5, x: 6 y: 6, x: 6 y: 5, x: 4 y: 4, x: 4