Logical Operators Operator Precedence

51 The result is True if either or both the operands is True ; otherwise, the result is False . OrElse performs logical short-circuiting: if the first operand of the expression is True , the second operand is not evaluated. Xor Performs a Boolean exclusive or operation on the bits. The result bit is 1 if either of the source bits is 1 , but not both. Not Performs a Boolean Not operation on the bits in the operand. This is a unary operator. The result is 1 if the source bit is and if the source bit is 1 .

2.12.6 Logical Operators

Logical operators are operators that require Boolean operands. They are: And The result is True if and only if both of the operands are True ; otherwise, the result is False . Or The result is True if either or both of the operands is True ; otherwise, the result is False . Xor The result is True if one and only one of the operands is True ; otherwise, the result is False . Not This is a unary operator. The result is True if the operand is False ; False if the operand is True .

2.12.7 Operator Precedence

Operator precedence defines the order in which operators are evaluated. For example, the expression 1 + 2 3 has the value 9 if the addition is performed first but has the value 7 if the multiplication is performed first. To avoid such ambiguity, languages must define the order in which operations are evaluated. Visual Basic .NET divides the operators into groups and defines each groups precedence relative to the others. Operators in higher-precedence groups are evaluated before operators in lower- precedence groups. Operators within each group have the same precedence relative to each other. When an expression contains multiple operators from a single group, those operators are evaluated from left to right. Table 2- 6 shows Visual Basic .NETs operators, grouped by precedence from highest to lowest order of evaluation. Table 2-6. The precedence of Visual Basic .NETs operators Category Operator Arithmetic and Exponentiation 52 concatenation Negation Multiplication and division Integer division Modulus arithmetic Addition and subtraction, string concatenation + String concatenation Comparison operators Equality, inequality, greater than, less than, greater than or equal to, less than or equal to, Is , TypeOf , Like Logical and bitwise operators Negation Not Conjunction And , AndAlso Disjunction Or , OrElse , Xor Parentheses override the default order of evaluation. For example, in the expression 1 + 2 3 , the multiplication is performed before the addition, yielding a value of 7 . To perform the addition first, the expression can be rewritten as 1 + 2 3 , yielding a result of 9 .

2.12.8 Operator Overloading