Professional Documents
Culture Documents
Net
Operators Listed by Functionality
S.# Operators Description
1 Arithmetic These operators perform mathematical calculations.
2 Assignment These operators perform assignment operations.
3 Comparison These operators perform comparisons.
4 Concatenation These operators combine strings.
5 Logical/Bitwise These operators perform logical operations.
6 Bit Shift These operators perform arithmetic shifts on bit patterns.
1. Arithmetic Operators
The following are the arithmetic operators defined in Visual Basic .NET.
S.# Operators Description
1 ^ (Number ^ exponent) Raises a number to the power of another number.
2 * (Number1 * Number2) Multiplies two numbers.
3 / (Number1 / Number2) Divides two numbers and returns quotient in floating-point result.
4 \ (Number1 \ Number2) Divides two numbers and returns quotient in integer result.
5 Mod (Number1 Mod Number2) Divides two numbers and returns only the remainder.
6 + (expression1 + expression2) Adds two numbers. Also used to concatenate two strings.
7 - (expression1 - expression2) subtraction operator for the difference between two numbers.
Examples Of (Arithmetic Operators)
Module Module1
Sub Main()
Console.WriteLine(2 ^ 2) ‘4
Console.WriteLine(3 ^ 3 ^ 3) ‘19683
Console.WriteLine((-5) ^ 2) ‘25 (According Mathematic rule Even for +)
Console.WriteLine((-5) ^ 9) ‘-1953125 (According Mathematic rule odd for -)
Console.WriteLine()
Console.WriteLine(10 * 4) ‘40
Console.WriteLine()
Console.WriteLine(10 / 4) ‘2.5
Console.WriteLine(10 \ 4) ‘2
Console.WriteLine()
Console.WriteLine(10 Mod 5) ‘0
Console.WriteLine(10 Mod 3) ‘1
Console.WriteLine(12 Mod 4.3) ‘3.4
Console.WriteLine()
Console.WriteLine(10 + 4) ‘14
Console.WriteLine(10 - 4) ‘6
Console.ReadLine()
End Sub
End Module
1 of 7
Microsoft Visual Basic .Net
2. Assignment Operators
The following are the Assignment operators defined in Visual Basic .NET.
S.# Operators Description
1 = (var=value) Used to assign a value to a variable or property.
2 ^=(var ^= expression) Raises the value of a variable to the power of an expression and assigns the
result back to the variable.
3 *=(var *= expression) Multiplies the value of a variable by the value of an expression and assigns
the result to the variable.
4 /=(var /= expression) Divides the value of a variable by the value of an expression and assigns the
floating-point result to the variable.
5 \=(var \= expression) Divides the value of a variable by the value of an expression and assigns the
integer result to the variable.
6 +=(var += expression) Adds the value of an expression to the value of a variable and assigns the
result to the variable. Also concatenates a String expression to a String
variable and assigns the result to the variable.
7 -=(var -= expression) Subtracts the value of an expression from the value of a variable and assigns
the result to the variable.
8 <<=(var >>=amount) Performs an arithmetic left shift on the value of a variable and assigns
the result back to the variable.
9 >>=(var >>=amount) Performs an arithmetic right shift on the value of a variable and
assigns the result back to the variable.
10 &= (var &= expression) Concatenates a String expression to a String variable and assigns the result
to the variable.
3 of 7
Microsoft Visual Basic .Net
Console.WriteLine(strvar1 + strvar2) ‘HelloDear
Console.WriteLine(intvar1 + strvar1) ‘Exception is thrown
Console.ReadLine()
End Sub
End Module
5. Logical/Bitwise Operators
S.# Operators Description
1 And Performs a logical conjunction on two expressions
2 Not Performs logical negation on an expression.
3 Or Used to perform a logical disjunction on two expressions
4 Xor Performs a logical exclusion operation on two expressions
5 AndAlso Performs short-circuiting logical conjunction on two expressions.
6 OrElse Perform short-circuiting logical disjunction on two expressions.
Chart for And , Not , Or , Xor Operators
expression1 expression2 Value of result Value of Value of Value of
S.#
is is And result Or result Not result Xor
1 True True True True False False
2 True False False True False True
3 False True False True True True
4 False False False False True False
Chart for AndAlso Operators
S.# expression1 is expression2 is Value of result AndAlso
1 True (not evaluated) False
2 False True False
3 False False False
Chart for OrElse Operators
S.# expression1 is expression2 is Value of result OrElse
1 True True True
2 False True False
3 False (not evaluated) False
Examples Of (Logical/Bitwise Operators)
Module Module1
Sub Main()
Dim A As Integer = 10
Dim B As Integer = 8
Dim C As Integer = 6
Dim myCheck As Boolean
myCheck = A > B And B > C ' Returns True.
Console.WriteLine(myCheck)
myCheck = B > A And B > C ' Returns False.
Console.WriteLine(myCheck)
myCheck = Not (A > B) ' Returns False.
Console.WriteLine(myCheck)
myCheck = Not (B > A) ' Returns True.
Console.WriteLine(myCheck)
myCheck = A > B Or B > C ' Returns True.
Console.WriteLine(myCheck)
4 of 7
Microsoft Visual Basic .Net
myCheck = B > A Or B > C ' Returns True.
Console.WriteLine(myCheck)
myCheck = B > A Or C > B ' Returns False.
Console.WriteLine(myCheck)
myCheck = A > B Xor B > C ' Returns False.
Console.WriteLine(myCheck)
myCheck = B > A Xor B > C ' Returns True.
Console.WriteLine(myCheck)
myCheck = B > A Xor C > B ' Returns False.
Console.WriteLine(myCheck)
myCheck = A > B AndAlso B > C ' True.
Console.WriteLine(myCheck)
myCheck = B > A AndAlso B > C ' False. Second expression not evaluated.
Console.WriteLine(myCheck)
myCheck = A > B AndAlso C > B ' False. Second expression evaluated.
Console.WriteLine(myCheck)
myCheck = A > B OrElse B > C ' True. Second expression is not evaluated.
Console.WriteLine(myCheck)
myCheck = B > A OrElse B > C ' True. Second expression is evaluated.
Console.WriteLine(myCheck)
myCheck = B > A OrElse C > B ' False.
Console.WriteLine(myCheck)
Console.ReadLine()
End Sub
End Module
The shift amount for Result4 is calculated as 17 AND 15, which equals 1.
• The arithmetic and concatenation operators have the order of precedence described below, and all have
higher precedence than the comparison, logical, and bitwise operators.
• Comparison operators have equal precedence, and all have higher precedence than the logical and bitwise
operators, but lower precedence than the arithmetic and concatenation operators.
• Logical and bitwise operators have the order of precedence described below, and all have lower
precedence than the arithmetic, concatenation, and comparison operators.
• Operators with equal precedence are evaluated left to right in the order in which they appear in the
expression.
Operators are evaluated in the following order of precedence:
Arithmetic and Concatenation Operators
Exponentiation (^)
Unary negation (–)
Multiplication and division (*, /)
Integer division (\)
6 of 7
Microsoft Visual Basic .Net
Modulus arithmetic (Mod)
Addition and subtraction (+, –), string concatenation (+)
String concatenation (&)
Arithmetic bit shift (<<, >>)
Comparison Operators
All comparison operators (=, <>, <, <=, >, >=, Like, Is, TypeOf...Is)
Logical and Bitwise Operators
Negation (Not)
Conjunction (And, AndAlso)
Disjunction (Or, OrElse, Xor)
Note
The string concatenation operator (&) is not an arithmetic operator, but in precedence it is grouped with the
arithmetic operators.
The Is operator is an object reference comparison operator. It does not compare objects or their values; it checks
only to determine if two object variables refer to the same object.
When operators of equal precedence occur together in an expression, for example multiplication and division,
each operation is evaluated as it occurs from left to right. Parentheses can be used to override the order of
precedence and to force some parts of an expression to be evaluated before others. Operations within parentheses
are always performed before those outside. Within parentheses, however, operator precedence is maintained. The
following example illustrates this:
7 of 7