- Operator (Visual Basic)
Returns the difference between two numeric expressions or the negative value of a numeric expression.
expression1 – expression2
- or -
– expression1
Parts
- expression1
Required. Any numeric expression.
- expression2
Required unless the – operator is calculating a negative value. Any numeric expression.
Result
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.
Supported Types
All numeric types, including the unsigned and floating-point types and Decimal.
Remarks
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.
Note
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 Operator Procedures.
Example
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.
See Also
Reference
-= Operator (Visual Basic)
Arithmetic Operators (Visual Basic)
Operator Precedence in Visual Basic
Operators Listed by Functionality