CodeSteps

Python, C, C++, C#, PowerShell, Android, Visual C++, Java ...

C# – Unary operators – Unary plus, minus and logical negation operators

C# unary operators takes single operand as input and produce the value. These operands are constants, expressions or variables. Please note that, do not confuse with Arithmetic plus (+) and minus (-) operators. Arithmetic operators takes more than one operand as an input; whereas, unary operators takes only one operand as an input.

Through this article, we are going to discuss about unary plus, minus and logical negation operators.

Unary plus (+) operator

This operator returns the value of its operand. It doesn’t evaluate anything; just it returns the value of the operand.

Console.WriteLine(+4.6692);

Unary minus (-) operator

This operator is used to negate the value of its operand. Positive values return as negative values and vice versa.

Console.WriteLine(-2.7182818284);

Logical Negation (!) operator

Logical negation returns the true value of the operand as false and false value of the operand as true. This operator mostly we use in logical expressions.

Console.WriteLine(!true);

(Raju)

C# – Unary operators – Unary plus, minus and logical negation operators

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top