Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

-- Operator (C# Reference)

The decrement operator (--) decrements its operand by 1. The decrement operator can appear before or after its operand: --variable and variable--. The first form is a prefix decrement operation. The result of the operation is the value of the operand "after" it has been decremented. The second form is a postfix decrement operation. The result of the operation is the value of the operand "before" it has been decremented.

Numeric and enumeration types have predefined decrement operators.

User-defined types can overload the -- operator (see operator). Operations on integral types are generally allowed on enumeration.

class MainClass5
{
    static void Main()
    {
        double x;
        x = 1.5;
        Console.WriteLine(--x);
        x = 1.5;
        Console.WriteLine(x--);
        Console.WriteLine(x);
    }
}
/*
Output:
0.5
1.5
0.5
*/

Community Additions

ADD
Show:
© 2015 Microsoft