++ Operator (C# Reference)

The unary increment operator ++ increments its operand by 1. It's supported in two forms: the postfix increment operator, x++, and the prefix increment operator, ++x.

Postfix increment operator

The result of x++ is the value of x before the operation, as the following example shows:

int i = 3;
Console.WriteLine(i);   // output: 3
Console.WriteLine(i++); // output: 3
Console.WriteLine(i);   // output: 4

Prefix increment operator

The result of ++x is the value of x after the operation, as the following example shows:

double a = 1.5;
Console.WriteLine(a);   // output: 1.5
Console.WriteLine(++a); // output: 2.5
Console.WriteLine(a);   // output: 2.5

Remarks

The increment operator is predefined for all integral types (including the char type), floating-point types, and any enum type.

An operand of the increment operator must be a variable, a property access, or an indexer access.

Operator overloadability

User-defined types can overload the ++ operator.

C# language specification

For more information, see the Postfix increment and decrement operators and Prefix increment and decrement operators sections of the C# language specification.

See also