Increment and Decrement Operators in C#

CsharpProgrammingServer Side Programming

Increment operator increases integer value by one i.e.

int a = 10;
a++;
++a;

Decrement operator decreases integer value by one i.e.

int a = 20;
a--;
--a;

The following is an example demonstrating increment operator −

Example

 Live Demo

using System;

class Program {
   static void Main() {
      int a, b;

      a = 10;
      Console.WriteLine(++a);
      Console.WriteLine(a++);

      b = a;
      Console.WriteLine(a);
      Console.WriteLine(b);
   }
}

Output

11
11
12
12

The following is an example demonstrating decrement operator −

int a, b;
a = 10;

// displaying decrement operator result
Console.WriteLine(--a);
Console.WriteLine(a--);

b = a;
Console.WriteLine(a);
Console.WriteLine(b);
raja
Published on 16-Aug-2018 10:21:48
Advertisements