C# Increment and Decrement Operators

Description

The increment and decrement operators (++, --) increment and decrement numeric types by 1.

The operator can either precede or follow the variable which update the variable before or after the expression is evaluated.

Syntax

To place C# Increment and Decrement Operators before the variable.


++variable;
--variable;

To place C# Increment and Decrement Operators after the variable.


variable--;
variable++;

Example

For example:


int x = 0; /*from  w  w w  .  j a v  a2 s . c  o m*/
Console.WriteLine (x++);   // Outputs 0; x is now 1 
Console.WriteLine (++x);   // Outputs 2; x is now 2 
Console.WriteLine (--x);   // Outputs 1; x is now 1 





















Home »
  C# Tutorial »
    C# Language »




C# Hello World
C# Operators
C# Statements
C# Exception