-- Operator (C# Reference)

The unary decrement operator -- decrements its operand by 1. It's supported in two forms: the postfix decrement operator, x--, and the prefix decrement operator, --x.

Postfix decrement 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: 2

Prefix decrement 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: 0.5
Console.WriteLine(a);   // output: 0.5

Remarks

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

An operand of the decrement 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