## Operators of VB.NET

An operator is a symbol that instruct computer to perform certain kind of operation on its operands.

Following are the various types of operators supported by VB.NET:

(1) Arithmetic Operator

(2) Comparison Operator

(3) String Concatenation Operator

(4) Logical Operator

(5) Assignment Operator

## (1) Arithmetic Operator:

Following are the list of Arithmetic operators supported by VB.NET: Suppose we declare three variables:

a = 5

b = 2

Operator | Meaning | Example |

+ |
It performs arithmetic addition of two operands and returns the result. |
c = a + b It returns 7 |

- |
It performs arithmetic subtraction of two operands and returns the result. |
c = a - b It returns 3 |

* |
It performs arithmetic multiplication of two operands and returns the result. |
c = a * b It returns 10 |

/ |
It performs arithmetic division of two operands and returns the result. | c = a / b It returns 2.5 |

\ |
It performs arithmetic division of two operands and returns the result as an integer. It means it will ignore the result after the decimal point. |
c = a \ b |

^ |
It raises one operand with another operand and returns the result. It means find the exponent value of one operand with respect to another operand. |
c = a ^ b |

Mod |
It performs arithmetic division of two operands and returns the remainder of the division as result. |
C = A Mod B |

## (2) Comparison Operator

Following are the list of Comparison operators supported by VB.NET:

Suppose we declare two variables:

a = 5

b = 2

Operator |
Meaning |
Example |

= |
It compares two operands and returns TRUE if both operands are equal otherwise it returns FALSE. |
A = B It returns FALSE |

<> |
It compares two operands and returns TRUE if both operands are not equal otherwise it returns FALSE. |
A <> B It returns TRUE |

< |
It compares two operands and returns TRUE if Operand1 is less then Operand2 otherwise it returns FALSE. |
A < B |

> |
It compares two operands and returns TRUE if Operand1 is greater then Operand2 otherwise it returns FALSE. | A > B |

<= |
It compares two operands and returns TRUE if Operand1 is less then or equal to Operand2 otherwise it returns FALSE. | A <= B |

>= |
It compares two operands and returns TRUE if Operand1 is greater then or equal to Operand2 otherwise it returns FALSE. | A >= B |

Like |
Like operator works for string operands. It is used to determine weather string match with particular pattern or not. Pattern can be defined using following characters: |
Dim a as string=”Hello” |

## (3)String Concatenation Operator

Following are the list of concatenation operators supported by VB.NET.

Consider Following Example:

Dim d as integer, e as integer, f as integer

a = “Hello”

b = “How Are You”

d = 2

e = 3

Operator | Meaning | Example |

& |
It Concate two operands or string. |
c = a & b |

+ |
It Concate two operands or string. |
c = a + b |

## (4) Logical Operator

Following are the list of Logical Operators supported by VB.NET:

Consider Following Example:

a = true

b = false

Operator |
Meaning |
Example |

And |
It accepts Boolean value or condition as operands and returns TRUE if both operands are TRUE otherwise it returns FALSE. |
c = a And b |

Or |
It accepts Boolean value or condition as operands and returns TRUE if any of the operand is TRUE otherwise it returns FALSE. |
c = a Or |

Not |
It reverses the logical state of its operand or condition. If operand or condition is true then it returns false. If operand or condition is false then it returns true. |
c = Not (a And b) |

Xor |
It accepts Boolean value or condition as operands and returns FALSE if both operands are same otherwise it returns TRUE. |
c = a Xor b |

AndAlso |
It works same as AND operator but It will not evaluate second operand if first operand is FALSE. |
c = a AndAlso b |

OrElse |
It works same as OR operator but It will not evaluate second operand if first operand is TRUE. |
c = a OrElse b |

## (5) Assignment Operator

Following are the list of Assignment Operators supported by VB.NET:

Operator |
Meaning |
Example |

= |
Assign value from the right side operand or expression to the operand on left side. |
c = a * b |

+= |
Add right operand to left operand and assign result to left operand. |
a = a + b |

-= |
Subtract right operand from left operand and assign result to left operand. |
a = a - b |

*= |
Multiply right operand with left operand and assign result to left operand. |
a = a * b |

/= |
Divide left operand by right operand and assign result to left operand. |
a = a / b |

\= |
Divide left operand by right operand and assign result to left operand. |
a = a \ b |

^= |
Raise left operand to the power of right operand and assign result to left operand. |
a = a ^ b |

&= |
Concate left operand with right operand and assign result to left operand. |
a = a & b |