# VB.net Operators – How Many Types of Operators Used in VB.net

## What is VB.net Operators?

The VB.net Operators is a symbol that instructs the compiler to carry out particular logical or mathematical operations.

The Operator symbol is used in VB.net programming to execute various operations on variables. The many Types of Operators in VB.net assist with applying logical and mathematical operations to data values. In the VB.net programming language, the Operator precedence is used to specify the order in which several Operators are executed.

In order for you to test your VB.net Code provided in this lesson, you must test the code in your code editor. But if you wish to run this code online, we also have an Online Compiler in VB.net for you to test your VB.net Code for free.

Operator is a specialized symbol in VB.net that instructs the compiler to apply a particular logical or mathematical operation to the data values. An operand is the data value itself, which can be either a variable or a constant. The operator applies different operations on the operand.

## How Many Types of Operators Used in VB.net?

The following Types of Operators Used in VB.net extensive built-in operator library.

• Arithmetic Operators
• Comparison Operators
• Logical/Bitwise Operators
• Bit Shift Operators
• Assignment Operators
• Miscellaneous Operators

### VB.net Arithmetic Operators

The Arithmetic Operators in VB.net, used to perform mathematical operations such as subtraction, addition, multiplication, division, etc. on the operands in VB.net.

Following table shows all the arithmetic operators supported by VB.net.

Example Program of VB.net Arithmetic Operators:

``````Imports System
Module Arithmetic_Operator
Sub Main()
'Declare a, b And c as integer Data Type()
Dim a, b, c As Integer
Dim d As Single
a = 17
b = 4
' Use of + Operator
c = a + b
Console.WriteLine(" Sum of a + b is {0}", c)

'Use of - Operator
c = a - b
Console.WriteLine(" Subtraction of a - b is {0}", c)

'Use of * Operator
c = a * b
Console.WriteLine(" Multiplication of a * b is {0}", c)

'Use of / Operator
d = a / b
Console.WriteLine(" Division of a / b is {0}", d)

'Use of \ Operator
c = a \ b
Console.WriteLine(" Similar to division Operator (return only integer value) of a - b is {0}", c)

'Use of Mod Operator
c = a Mod b
Console.WriteLine(" Modulus of a Mod b is {0}", c)

'Use of ^ Operator
c = a ^ b
Console.WriteLine(" Power of a ^ b is {0}", c)
Console.WriteLine("Press any key to exit...")
Console.ReadKey()
End Sub
End Module  ``````

When the above code is compiled and executed, it produces the following result:

Sum of a + b is 21
Subtraction of a – b is 13
Multiplication of a * b is 68
Division of a / b is 4.25
Similar to division Operator (return only integer value) of a – b is 4
Modulus of a Mod b is 1
Power of a ^ b is 83521
Press any key to exit…

Test your Code Here!

### Comparison Operator in VB.net

The Comparison Operator in VB.net compares the values of two variables or operands for a variety of conditions, including greater, less than, or equal, etc., and depending on the condition, it produces a Boolean value of true or false.

Following table shows all the Comparison Operators in VB.net.

Example Program of VB.net Comparison Operator:

``````Imports System
Module Comparison_Operator
Sub Main()
'declaration of Integer, Object and String Data Type variables
Dim x As Integer = 5
Dim y As Integer = 10
Dim Result, obj, obj2 As Object
Dim str, str2 As String
str = "ITSOURCECODE"
str2 = "ITSOURCECODE"
obj = 10
obj2 = 20

Console.WriteLine(" Program of Comparison Operator")
'Use of > Operator
Console.WriteLine(" Output of x > y is {0}", x > y)

'Use of < Operator
Console.WriteLine(" Output of x < y is {0}", x < y)

'Use of = Operator
Console.WriteLine(" Output of x = y is {0}", x = y)

'Use of <> Operator
Console.WriteLine(" Output of x <> y is {0}", x <> y)

'Use of >= Operator
Console.WriteLine(" Output of x >= y is {0}", x >= y)

'Use of <= Operator
Console.WriteLine(" Output of x <= y is {0}", x <= y)

'Use of Is Operator
Result = obj Is obj2
Console.WriteLine(" Output of obj Is obj2 is {0}", Result)

'Use of Is Operator
Result = obj IsNot obj2
Console.WriteLine(" Output of obj IsNot obj2 is {0}", Result)

'Use of Like Operator
Result = str Like str2
Console.WriteLine(" Output of str Like str2 is {0}", Result)

Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
End Module``````

When the above code is compiled and executed, it produces the following result:

Program of Comparison Operator
Output of x > y is False
Output of x < y is True Output of x = y is False Output of x <> y is True
Output of x >= y is False
Output of x <= y is True
Output of obj Is obj2 is False
Output of obj IsNot obj2 is True
Output of str Like str2 is True
Press any key to exit…

Test your Code Here!

### Logical/Bitwise Operators in VB.net

The logical and bitwise Operators in VB.net work with Boolean (true or false) conditions, and if the conditions become true, it returns a Boolean value. The following are the logical and bitwise Operators used to perform the various logical operations such as And, Or, Not, etc. on the operands (variables). Suppose there are two operand A and B, where A is True, and B is False.

Following table shows all the Logical/Bitwise Operators in VB.net.

Example Program of VB.net Logical/Bitwise Operators:

``````Imports System
Module Logic_Bitwise
Sub Main()
Dim A As Boolean = True
Dim B As Boolean = False
Dim c, d As Integer
c = 10
d = 20

'Use of And Operator
If A And B Then
Console.WriteLine(" Operands A And B are True")
End If

'Use of Or Operator
If A Or B Then
Console.WriteLine(" Operands A Or B are True")
End If

'Use of Xor Operator
If A Xor B Then
Console.WriteLine(" Operands A Xor B is True")
End If

'Use of And Operator
If c And d Then
Console.WriteLine(" Operands c And d is True")
End If

'Use of Or Operator
If c Or d Then
Console.WriteLine(" Operands c Or d is True")
End If

'Use of AndAlso Operator
If A AndAlso B Then
Console.WriteLine(" Operand A AndAlso B is True")
End If

'Use of OrElse Operator
If A OrElse B Then
Console.WriteLine(" Operand A OrElse B is True")
End If

'Use of Not Operator
If Not (A And B) Then
Console.WriteLine(" Output of Not (A And B) is True")
End If

Console.WriteLine(" Press any key to exit?")
Console.ReadKey()
End Sub
End Module ``````

When the above code is compiled and executed, it produces the following result:

Operands A Or B are True
Operands A Xor B is True
Operands c Or d is True
Operand A OrElse B is True
Output of Not (A And B) is True
Press any key to exit?

Test your Code Here!

### Bit Shift Operators in VB.net

The Bit Shift Operators in VB.net are used to perform the bit shift operations on binary values either to the right or to the left.

Following table shows all the Bit Shift Operators in VB.net.

Example Program of Bit Shift Operators in VB.net:

``````Imports System
Module Bitshift_Operator
Sub Main()
Dim x, y, z As Integer
x = 12
y = 25
Dim a, b As Double
a = 5 ' a = 5(00000101)
b = 9 ' b = 9(00001001)

' Use of And Operator
z = x And y
Console.WriteLine(" BitShift Operator x And y is {0}", z)

'Use of Or Operator
z = x Or y
Console.WriteLine(" BitShift Operator x Or y is {0}", z)

z = x Xor y
Console.WriteLine(" BitShift Operator x Xor y is {0}", z)

z = Not y
Console.WriteLine(" BitShift Operator Not y is {0}", z)

'Use of << Left-Shift Operator
' Output is 00001010
Console.WriteLine(" Bitwise Left Shift Operator - a<<1 = {0}", a << 1)

'Output is 00010010
Console.WriteLine(" Bitwise Left Shift Operator - b<<1 = {0}", b << 1)

'Use of >> Right-Shift Operator
'Output is 00000010
Console.WriteLine(" Bitwise Right Shift Operator - a>>1 = {0}", a << 1)

'Output is 00000100
Console.WriteLine(" Bitwise Right Shift Operator - b>>1 = {0}", a << 1)

Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
End Module ``````

When the above code is compiled and executed, it produces the following result:

BitShift Operator x And y is 8
BitShift Operator x Or y is 29
BitShift Operator x Xor y is 21
BitShift Operator Not y is -26
Bitwise Left Shift Operator – a<<1 = 10 Bitwise Left Shift Operator – b<<1 = 18 Bitwise Right Shift Operator – a>>1 = 10
Bitwise Right Shift Operator – b>>1 = 10
Press any key to exit…

Test your Code Here!

### Assignment Operators in VB.net

The Assignment Operators in VB.net are used to assign the value to variables.

Following table shows all the Assignment Operators in VB.net.

Example Program of VB.net Assignment Operators:

``````Imports System
Module Assign_Operator
Sub Main()
'Declare variable and b As Integer
Dim A As Integer = 5
Dim B As Integer
Dim Str, name As String
name = "come"
Str = "Wel"

'Use of = Operator
B = A
Console.WriteLine(" Assign value A to B is {0}", B)

'Use of += Operator
B += A
Console.WriteLine(" Output of B += A is {0}", B)

'Use of -= Operator
B -= A
Console.WriteLine(" Output of B -= A is {0}", B)

'Use of *= Operator
B *= A
Console.WriteLine(" Output of B *= A is {0}", B)

'Use of /= Operator
B /= A
Console.WriteLine(" Output of B /= A is {0}", B)

'Use of = Operator
B \= A
Console.WriteLine(" Output of B \= A is {0}", B)

'Use of ^= Operator
B ^= A
Console.WriteLine(" Output of B ^= A is {0}", B)

'Use of &= Operator
Str &= name
Console.WriteLine(" Output of Str &= name is {0}", Str)

Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
End Module``````

When the above code is compiled and executed, it produces the following result:

Assign value A to B is 5
Output of B += A is 10
Output of B -= A is 5
Output of B *= A is 25
Output of B /= A is 5
Output of B = A is 1
Output of B ^= A is 1
Output of Str &= name is Welcome
Press any key to exit…

Test your Code Here!

### Miscellaneous Operators in VB.net

Miscellaneous Operators in VB.net It is applied to an operand in an asynchronous method or lambda expression to suspend execution of the method until the awaited task completes.

Following table shows all the Miscellaneous Operators in VB.net.

Example Program of VB.net Miscellaneous Operators:

``````Imports System
Module Misc_Operator
Sub Main()
' Initialize a variable
Dim a As Integer = 50
' GetType of the Defined Type
Console.WriteLine(GetType(Double).ToString())
Console.WriteLine(GetType(Integer).ToString())
Console.WriteLine(GetType(String).ToString())
Console.WriteLine(GetType(Single).ToString())
Console.WriteLine(GetType(Decimal).ToString())

'Use of Function()
Dim multiplywith10 = Function(sum As Integer) sum * 10
Console.WriteLine(multiplywith10(10))
Console.WriteLine(If(a >= 0, "Negative", "Positive"))

Console.WriteLine(" Press any key to exit...")
Console.ReadLine()

End Sub
End Module  ``````

When the above code is compiled and executed, it produces the following result:

System.Double
System.Int32
System.String
System.Single
System.Decimal
100
Negative
Press any key to exit…

Test your Code Here!

## Summary

• An Operators in VB.Net refers to a symbol that instructs the compiler to perform a specific logical or mathematical manipulation.
• VB.Net supports the use of operators to perform arithmetic, logical, and comparison operations.
• Operators are divided into various categories.
• Operators operate on operands.
• We can use arithmetic operators to perform various mathematical operations in VB.NET.
• Comparison operators in VB.net are used for making comparisons between variables.
• Logical operators in VB.net help us in making logical decisions.