ASP.NetMiscellaneous Feature ASP.NET Scripting Visual BasicVB.Net Elements OperatorArithmetic OperatorCompare OperatorConcatenation Operator Draft for Information Only
Content
VB.NET Logical/Bitwise Operators
VB.NET Logical/Bitwise OperatorsThe supporting VB.NET Logical/Bitwise Operators are And, Not, Or, Xor, AndAlso, OrElse, IsFalse, IsTrue. And OperatorPerforms a logical conjunction on two Boolean expressions, or a bitwise conjunction on two numeric expressions. Syntaxresult = expression1 And expression2 Partsresult: Required. Any Boolean or numeric expression. For Boolean comparison, result is the logical conjunction of two Boolean values. For bitwise operations, result is a numeric value representing the bitwise conjunction of two numeric bit patterns. expression1" Required. Any Boolean or numeric expression. expression2: Required. Any Boolean or numeric expression. RemarksFor Boolean comparison, result is True if and only if both expression1 and expression2 evaluate to True. The following table illustrates how result is determined.
Note In a Boolean comparison, the And operator always evaluates both expressions, which could include making procedure calls. The AndAlso Operator performs shortcircuiting, which means that if expression1 is False, then expression2 is not evaluated. When applied to numeric values, the And operator performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following table.
Note Since the logical and bitwise operators have a lower precedence than other arithmetic and relational operators, any bitwise operations should be enclosed in parentheses to ensure accurate results. Data TypesIf the operands consist of one Boolean expression and one numeric expression, Visual Basic converts the Boolean expression to a numeric value (–1 for True and 0 for False) and performs a bitwise operation. For a Boolean comparison, the data type of the result is Boolean. For a bitwise comparison, the result data type is a numeric type appropriate for the data types of expression1 and expression2. See the "Relational and Bitwise Comparisons" table in Data Types of Operator Results. Note The And 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
Not OperatorPerforms logical negation on a Boolean expression, or bitwise negation on a numeric expression. Syntaxresult = Not expression Partsresult: Required. Any Boolean or numeric expression. expression: Required. Any Boolean or numeric expression. RemarksFor Boolean expressions, the following table illustrates how result is determined.
For numeric expressions, the Not operator inverts the bit values of any numeric expression and sets the corresponding bit in result according to the following table.
Note Since the logical and bitwise operators have a lower precedence than other arithmetic and relational operators, any bitwise operations should be enclosed in parentheses to ensure accurate execution. Data TypesFor a Boolean negation, the data type of the result is Boolean. For a bitwise negation, the result data type is the same as that of expression. However, if expression is Decimal, the result is Long. OverloadingThe Not operator can be overloaded, which means that a class or structure can redefine its behavior when its 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
Or OperatorPerforms a logical disjunction on two Boolean expressions, or a bitwise disjunction on two numeric expressions. Syntaxresult = expression1 Or expression2 Partsresult: Required. Any Boolean or numeric expression. For Boolean comparison, result is the inclusive logical disjunction of two Boolean values. For bitwise operations, result is a numeric value representing the inclusive bitwise disjunction of two numeric bit patterns. expression1: Required. Any Boolean or numeric expression. expression2: Required. Any Boolean or numeric expression. RemarksFor Boolean comparison, result is False if and only if both expression1 and expression2 evaluate to False. The following table illustrates how result is determined.
Note In a Boolean comparison, the Or operator always evaluates both expressions, which could include making procedure calls. The OrElse Operator performs shortcircuiting, which means that if expression1 is True, then expression2 is not evaluated. For bitwise operations, the Or operator performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following table.
Note Since the logical and bitwise operators have a lower precedence than other arithmetic and relational operators, any bitwise operations should be enclosed in parentheses to ensure accurate execution. Data TypesIf the operands consist of one Boolean expression and one numeric expression, Visual Basic converts the Boolean expression to a numeric value (–1 for True and 0 for False) and performs a bitwise operation. For a Boolean comparison, the data type of the result is Boolean. For a bitwise comparison, the result data type is a numeric type appropriate for the data types of expression1 and expression2. See the "Relational and Bitwise Comparisons" table in Data Types of Operator Results. OverloadingThe Or 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
Xor OperatorPerforms a logical exclusion on two Boolean expressions, or a bitwise exclusion on two numeric expressions. Syntaxresult = expression1 Xor expression2 Parts
result expression1: Required. Any Boolean or numeric expression. expression2: Required. Any Boolean or numeric expression. RemarksFor Boolean comparison, result is True if and only if exactly one of expression1 and expression2 evaluates to True. That is, if and only if expression1 and expression2 evaluate to opposite Boolean values. The following table illustrates how result is determined.
Note In a Boolean comparison, the Xor operator always evaluates both expressions, which could include making procedure calls. There is no shortcircuiting counterpart to Xor, because the result always depends on both operands. For shortcircuiting logical operators, see AndAlso Operator and OrElse Operator. For bitwise operations, the Xor operator performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following table.
Note Since the logical and bitwise operators have a lower precedence than other arithmetic and relational operators, any bitwise operations should be enclosed in parentheses to ensure accurate execution. For example, 5 Xor 3 is 6. To see why this is so, convert 5 and 3 to their binary representations, 101 and 011. Then use the previous table to determine that 101 Xor 011 is 110, which is the binary representation of the decimal number 6. Data TypesIf the operands consist of one Boolean expression and one numeric expression, Visual Basic converts the Boolean expression to a numeric value (–1 for True and 0 for False) and performs a bitwise operation. For a Boolean comparison, the data type of the result is Boolean. For a bitwise comparison, the result data type is a numeric type appropriate for the data types of expression1 and expression2. See the "Relational and Bitwise Comparisons" table in Data Types of Operator Results. OverloadingThe Xor 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 you understand its redefined behavior. For more information, see Operator Procedures. See also
AndAlso OperatorPerforms shortcircuiting logical conjunction on two expressions. Syntax
VB
result = expression1 AndAlso expression2 Partsresult: Required. Any Boolean expression. The result is the Boolean result of comparison of the two expressions. expression1: Required. Any Boolean expression. expression2: Required. Any Boolean expression. RemarksA logical operation is said to be shortcircuiting if the compiled code can bypass the evaluation of one expression depending on the result of another expression. If the result of the first expression evaluated determines the final result of the operation, there is no need to evaluate the second expression, because it cannot change the final result. Shortcircuiting can improve performance if the bypassed expression is complex, or if it involves procedure calls. If both expressions evaluate to True, result is True. The following table illustrates how result is determined.
Data TypesThe AndAlso operator is defined only for the Boolean Data Type. Visual Basic converts each operand as necessary to Boolean before evaluating the expression. If you assign the result to a numeric type, Visual Basic converts it from Boolean to that type such that False becomes 0 and True becomes 1. For more information, see Boolean Type Conversions OverloadingThe And Operator and the IsFalse Operator can be overloaded, which means that a class or structure can redefine their behavior when an operand has the type of that class or structure. Overloading the And and IsFalse operators affects the behavior of the AndAlso operator. If your code uses AndAlso on a class or structure that overloads And and IsFalse, be sure you understand their redefined behavior. For more information, see Operator Procedures. See also
OrElse OperatorPerforms shortcircuiting inclusive logical disjunction on two expressions. Syntaxresult = expression1 OrElse expression2 Partsresult: Required. Any Boolean expression. expression1: Required. Any Boolean expression. expression2: Required. Any Boolean expression. RemarksA logical operation is said to be shortcircuiting if the compiled code can bypass the evaluation of one expression depending on the result of another expression. If the result of the first expression evaluated determines the final result of the operation, there is no need to evaluate the second expression, because it cannot change the final result. Shortcircuiting can improve performance if the bypassed expression is complex, or if it involves procedure calls. If either or both expressions evaluate to True, result is True. The following table illustrates how result is determined.
Data TypesThe OrElse operator is defined only for the Boolean Data Type. Visual Basic converts each operand as necessary to Boolean before evaluating the expression. If you assign the result to a numeric type, Visual Basic converts it from Boolean to that type such that False becomes 0 and True becomes 1. For more information, see Boolean Type Conversions OverloadingThe Or Operator and the IsTrue Operator can be overloaded, which means that a class or structure can redefine their behavior when an operand has the type of that class or structure. Overloading the Or and IsTrue operators affects the behavior of the OrElse operator. If your code uses OrElse on a class or structure that overloads Or and IsTrue, be sure you understand their redefined behavior. For more information, see Operator Procedures. See also
IsFalse OperatorDetermines whether an expression is False. You cannot call IsFalse explicitly in your code, but the Visual Basic compiler can use it to generate code from AndAlso clauses. If you define a class or structure and then use a variable of that type in an AndAlso clause, you must define IsFalse on that class or structure. The compiler considers the IsFalse and IsTrue operators as a matched pair. This means that if you define one of them, you must also define the other one. Note The IsFalse operator can be overloaded, which means that a class or structure can redefine its behavior when its 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 alsoIsTrue OperatorDetermines whether an expression is True. You cannot call IsTrue explicitly in your code, but the Visual Basic compiler can use it to generate code from OrElse clauses. If you define a class or structure and then use a variable of that type in an OrElse clause, you must define IsTrue on that class or structure. The compiler considers the IsTrue and IsFalse operators as a matched pair. This means that if you define one of them, you must also define the other one. Compiler Use of IsTrueWhen you have defined a class or structure, you can use a variable of that type in a For, If, Else If, or While statement, or in a When clause. If you do this, the compiler requires an operator that converts your type into a Boolean value so it can test a condition. It searches for a suitable operator in the following order:
If you have not defined any conversion to Boolean or an IsTrue operator, the compiler signals an error. Note The IsTrue operator can be overloaded, which means that a class or structure can redefine its behavior when its 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 alsoSource/Reference
©sideway ID: 200800003 Last Updated: 3/8/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_{ 7} Manim_{ 115} Numeric_{ 19} Programming Web_{ 283} Unicode_{ 494} HTML_{ 65} CSS_{ 58} ASP.NET_{ 149} 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