Visual Basic .NET - Operators
Arithmetic Operators:
These operators are used for mathematical operations such as addition, subtraction, multiplication, division, and modulus.
Dim num1 As Integer = 10
Dim num2 As Integer = 5
Dim result As Integer
result = num1 + num2 ' addition
result = num1 - num2 ' subtraction
result = num1 * num2 ' multiplication
result = num1 / num2 ' division
result = num1 Mod num2 ' modulus
Comparison Operators:
These operators are used to compare two values and return a Boolean value.
Dim num1 As Integer = 10
Dim num2 As Integer = 5
Dim result As Boolean
result = num1 > num2 ' greater than
result = num1 < num2 ' less than
result = num1 >= num2 ' greater than or equal to
result = num1 <= num2 ' less than or equal to
result = num1 = num2 ' equal to
result = num1 <> num2 ' not equal to
Logical Operators:
These operators are used to perform logical operations on Boolean values.
Dim bool1 As Boolean = True
Dim bool2 As Boolean = False
Dim result As Boolean
result = bool1 And bool2 ' logical AND
result = bool1 Or bool2 ' logical OR
result = Not bool1 ' logical NOT
Assignment Operators:
These operators are used to assign a value to a variable.
Dim num1 As Integer = 10
Dim num2 As Integer = 5
num1 += num2 ' equivalent to num1 = num1 + num2
num1 -= num2 ' equivalent to num1 = num1 - num2
num1 *= num2 ' equivalent to num1 = num1 * num2
num1 /= num2 ' equivalent to num1 = num1 / num2
num1 Mod= num2 ' equivalent to num1 = num1 Mod num2
Bitwise Operators:
These operators are used to perform bitwise operations on binary numbers.
Dim num1 As Integer = 10
Dim num2 As Integer = 5
Dim result As Integer
result = num1 And num2 ' bitwise AND
result = num1 Or num2 ' bitwise OR
result = num1 Xor num2 ' bitwise XOR
result = Not num1 ' bitwise NOT
result = num1 << 2 ' left shift
result = num1 >> 2 ' right shift