Unary Operators

In contrast to binary operators, unary operators are only applied to one operand. The following sections look closer at the unary plus (+), the unary minus (-), the increment (++), and the decrement (--) operators.

Unary Plus and Unary Minus

The unary minus operator shown in the following

is not just a minus sign, as in the literals (like –18) we write on a piece of paper. It is an operator and will change the sign of the numerical expression to which it is applied. Consequently, if the variable height has the value 10, - height will return the value –10. If the value is –10, the result will be 10.

Note

When the unary minus operator ...

Get C# Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.