- Operator (Visual Basic)
Returns the difference between two numeric expressions or the negative value of a numeric expression.
expression1 – expression2
Required. Any numeric expression.
Required unless the
– operator is calculating a negative value. Any numeric expression.
The result is the difference between
expression2, or the negated value of
The result data type is a numeric type appropriate for the data types of
expression2. See the "Integer Arithmetic" tables in Data Types of Operator Results.
All numeric types. This includes the unsigned and floating-point types and
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.
– 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.
Dim binaryResult As Double = 459.35 - 334.9 Dim unaryResult As Double = -334.9
Following the execution of these statements,
binaryResult contains 124.45 and
unaryResult contains –334.90.