ASP.NetMiscellaneous Feature ASP.NET Scripting Visual BasicVB.Net Elements Operator Draft for Information Only
Content
VB.NET Arithmetic Operators
VB.NET Arithmetic OperatorsThe supporting VB.NET Arithmetic Operators are ^, *, /, \, Mod, + (unary and binary),  (unary and binary). ^ OperatorExponentiationOperator. Raises a number to the power of another number. Syntaxnumber ^ exponent Partsnumber: Required. Any numeric expression. exponent: Required. Any numeric expression. ResultThe result is number raised to the power of exponent, always as a Double value. Supported TypesDouble. Operands of any different type are converted to Double. RemarksVisual Basic always performs exponentiation in the Double Data Type. The value of exponent can be fractional, negative, or both. When more than one exponentiation is performed in a single expression, the ^ operator is evaluated as it is encountered from left to right. 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. See also
* OperatorMultiplication operator. Multiplies two numbers. Syntaxnumber1 * number2 Partsnumber1: Required. Any numeric expression. number2: Required. Any numeric expression. ResultThe result is the product of number1 and number2. Supported TypesAll numeric types, including the unsigned and floatingpoint types and Decimal. RemarksThe data type of the result depends on the types of the operands. The following table shows how the data type of the result is determined.
If an expression evaluates to Nothing, it is treated as zero. OverloadingThe * 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. See also
/ OperatorFloatingpointdivisionoperator. Divides two numbers and returns a floatingpoint result. Syntaxexpression1 / expression2 Partsexpression1: Required. Any numeric expression. expression2: Required. Any numeric expression. Supported TypesAll numeric types, including the unsigned and floatingpoint types and Decimal. ResultThe result is the full quotient of expression1 divided by expression2, including any remainder. The \ Operator (Visual Basic) returns the integer quotient, which drops the remainder. RemarksThe data type of the result depends on the types of the operands. The following table shows how the data type of the result is determined.
Before division is performed, any integral numeric expressions are widened to Double. If you assign the result to an integral data type, Visual Basic attempts to convert the result from Double to that type. This can throw an exception if the result does not fit in that type. In particular, see "Attempted Division by Zero" on this Help page. If expression1 or expression2 evaluates to Nothing, it is treated as zero. Attempted Division by ZeroIf expression2 evaluates to zero, the / operator behaves differently for different operand data types. The following table shows the possible behaviors.
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. See also
\ OperatorIntegerdivision operator. Divides two numbers and returns an integer result. Syntaxexpression1 \ expression2 Partsexpression1: Required. Any numeric expression. expression2: Required. Any numeric expression. Supported TypesAll numeric types, including the unsigned and floatingpoint types and Decimal. ResultThe result is the integer quotient of expression1 divided by expression2, which discards any remainder and retains only the integer portion. This is known as truncation. 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. The / Operator (Visual Basic) returns the full quotient, which retains the remainder in the fractional portion. RemarksBefore performing the division, Visual Basic attempts to convert any floatingpoint numeric expression to Long. If Option Strict is On, a compiler error occurs. If Option Strict is Off, an OverflowException is possible if the value is outside the range of the Long Data Type. The conversion to Long is also subject to banker's rounding. For more information, see "Fractional Parts" in Type Conversion Functions. If expression1 or expression2 evaluates to Nothing, it is treated as zero. Attempted Division by ZeroIf expression2 evaluates to zero, the \ operator throws a DivideByZeroException exception. This is true for all numeric data types of the operands. 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. See also
Mod operatorDivides two numbers and returns only the remainder. Syntaxnumber1 Mod number2 Partsnumber1: Required. Any numeric expression. number2: Required. Any numeric expression. Supported typesAll numeric types. This includes the unsigned and floatingpoint types and Decimal. ResultThe result is the remainder after number1 is divided by number2. For example, the expression 14 Mod 4 evaluates to 2. Note There is a difference between remainder and modulus in mathematics, with different results for negative numbers. The Mod operator in Visual Basic, the .NET Framework op_Modulus operator, and the underlying rem IL instruction all perform a remainder operation. The result of a Mod operation retains the sign of the dividend, number1, and so it may be positive or negative. The result is always in the range (number2, number2), exclusive. RemarksIf either number1 or number2 is a floatingpoint value, the floatingpoint remainder of the division is returned. The data type of the result is the smallest data type that can hold all possible values that result from division with the data types of number1 and number2. If number1 or number2 evaluates to Nothing, it is treated as zero. Related operators include the following:
Attempted division by zeroIf number2 evaluates to zero, the behavior of the Mod operator depends on the data type of the operands. An integral division throws a DivideByZeroException exception. A floatingpoint division returns NaN. Equivalent formulaThe expression a Mod b is equivalent to either of the following formulas: a  (b * (a \ b)) a  (b * Fix(a / b)) Floatingpoint imprecisionWhen you work with floatingpoint numbers, remember that they do not always have a precise decimal representation in memory. This can lead to unexpected results from certain operations, such as value comparison and the Mod operator. For more information, see Troubleshooting Data Types. OverloadingThe Mod operator can be overloaded, which means that a class or structure can redefine its behavior. If your code applies Mod to an instance of a class or structure that includes such an overload, be sure you understand its redefined behavior. For more information, see Operator Procedures. See also
+ OperatorAddition operator. Adds two numbers or returns the positive value of a numeric expression. Can also be used to concatenate two string expressions. Syntaxexpression1 + expression2  or  + expression1 Partsexpression1: Required. Any numeric or string expression. expression2: Required unless the + operator is calculating a negative value. Any numeric or string expression. ResultIf expression1 and expression2 are both numeric, the result is their arithmetic sum. If expression2 is absent, the + operator is the unary identity operator for the unchanged value of an expression. In this sense, the operation consists of retaining the sign of expression1, so the result is negative if expression1 is negative. If expression1 and expression2 are both strings, the result is the concatenation of their values. If expression1 and expression2 are of mixed types, the action taken depends on their types, their contents, and the setting of the Option Strict Statement. For more information, see the tables in "Remarks." Supported TypesAll numeric types, including the unsigned and floatingpoint types and Decimal, and String. RemarksIn general, + performs arithmetic addition when possible, and concatenates only when both expressions are strings. If neither expression is an Object, Visual Basic takes the following actions.
If one expression is an Object expression, Visual Basic takes the following actions.
If both expressions are Object expressions, Visual Basic takes the following actions (Option Strict Off only).
If either Object expression evaluates to Nothing or DBNull, the + operator treats it as a String with a value of "". Note When you use the + operator, you might not be able to determine whether addition or string concatenation will occur. Use the & operator for concatenation to eliminate ambiguity and to provide selfdocumenting code. OverloadingThe + 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. See also
 OperatorSubtraction operator. Returns the difference between two numeric expressions or the negative value of a numeric expression. Syntaxexpression1 – expression2  or  – expression1 Partsexpression1: Required. Any numeric expression. expression2: Required unless the – operator is calculating a negative value. Any numeric expression. ResultThe 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 TypesAll numeric types. This includes the unsigned and floatingpoint types and Decimal. RemarksIn 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. 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, make sure that you understand its redefined behavior. For more information, see Operator Procedures. See also
Source/Reference
©sideway ID: 200700031 Last Updated: 31/7/2020 Revision: 0 Ref: References
Latest Updated Links

Home_{ 5} Business Management HBR_{ 3} Information Recreation Hobbies_{ 8} Culture Chinese_{ 1097} English_{ 337} Reference_{ 67} Computer Hardware_{ 149} Software Application_{ 198} Digitization_{ 25} Latex_{ 6} Manim_{ 113} Numeric_{ 19} Programming Web_{ 283} Unicode_{ 494} HTML_{ 65} CSS_{ 58} ASP.NET_{ 145} OS_{ 389} DeskTop_{ 7} Python_{ 19} Knowledge Mathematics Formulas_{ 8} Algebra_{ 25} Number Theory_{ 206} Trigonometry_{ 18} Geometry_{ 21} Calculus_{ 67} Complex Analysis_{ 21} Engineering Tables_{ 8} Mechanical Mechanics_{ 1} Rigid Bodies Statics_{ 92} Dynamics_{ 37} Fluid_{ 5} Fluid Kinematics_{ 5} Control Process Control_{ 1} Acoustics_{ 19} FiniteElement_{ 2} Physics Electric_{ 27} Biology_{ 1} Geography_{ 1} 
Copyright © 20002020 Sideway . All rights reserved Disclaimers last modified on 06 September 2019