|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 (Visual Basic)
Returns the difference between two numeric expressions or the negative value of a numeric expression.
In the first usage shown in the preceding syntax, the – operator is the binary arithmetic subtraction operator for the difference between two numeric expressions.
In the second usage shown in the preceding syntax, the – operator is the unary negation operator for the negative value of an expression. In this sense, the negation consists of reversing the sign of expression1, so the result is positive if expression1 is negative.
If either expression evaluates to Nothing, the – operator treats it as zero.
The – operator can be overloaded, which means that a class or structure can redefine its behavior when an operand has the type of that class or structure. If your code uses this operator on such a class or structure, be sure you understand its redefined behavior. For more information, see.
The following example uses the – operator to calculate and return the difference between two numbers, and then to negate a number.
Following the execution of these statements, binaryResult contains 124.45 and unaryResult contains –334.90.