C# Increment and Decrement Operators
In this chapter you will learn:
- What are C# Increment and Decrement Operators
- How to use C# Increment and Decrement Operators
- Example for 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 ava2 s.co 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
Next chapter...
What you will learn in the next chapter:
- Use % operator to get remainder
- Example for C# Remainder operator
- How to use remainder operator to determine smallest single-digit factor