|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. ArchiveDisclaimer|
- Operator (Visual Basic)
Returns the difference between two numeric expressions or the negative value of a numeric expression.
The result is the difference between expression1 and expression2, or the negated value of expression1.
The result data type is a numeric type appropriate for the data types of expression1 and expression2. See the "Integer Arithmetic" tables in Data Types of Operator Results.
In the first usage shown in the syntax shown previously, the – operator is the binary arithmetic subtraction operator for the difference between two numeric expressions.
In the second usage shown in the syntax shown previously, 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 that 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, make sure that you understand its redefined behavior. For more information, see Operator Procedures.
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.