**Table of Contents**hide

## Operators in VB .Net

#### Introduction

- Operators are a very important part of VB .Net Programming.

#### Definition

- An operator is a symbol that performs specific mathematical or logical manipulations on a given operands.

#### Type of Operators in VB .Net

- VB.Net has rich in built-in operators. These are –
##### Arithmetic Operators

- Arithmetic operators are used for performing common mathematical operations.
- These operators are –

Operator Symbol | Description | Example |

+ | Adds two operands | x + y |

– | Subtracts second operand from the first | x – y |

* | Multiplies both operands | x * y |

/ | Divides one operand by another and returns a floating-point result | x / y |

\ | Divides one operand by another and returns an integer result | x \ y |

MOD | Modulus division that gives remainder as result after an integer division | x MOD y (remainder of x/y) |

^ | Exponent operator that raises one operand to the power of another | x ^ y or x^{y} (x to the power y) |

#### Comparison Operators

- Comparison operators are basically used to compare different values and normally return a Boolean value in the form of either True or False depending upon the condition verified.
These operators are –

**Operator Symbol****Description****Example****=**Equality symbol that checks and returns True if both values are the same. x = y **<>**Non-Equality symbol that checks and returns True if both values are unequal. x < > y **>**Greater than symbol that checks and returns true if the first value is greater than the second value x > y **<**Less than symbol that checks and returns true if the first value is less than second value x < y **>=**Greater than equal to symbol that checks for two conditions and return true, If the first value is greater than or equal to the second value. x >= y **<=**Less than equal to symbol that Checks for two conditions and returns true, If the first value is less than or equal to the second value. x <= y **Is**Compares two object variables for reference and return true if the same object reference. **IsNot**Compares two object variables for reference and return false If the different object reference. **Like**Compares a string against a specific pattern.

#### Logical Operators

| Description | Example |

And | The And Operator verifies, whether both the operands are true then returns True. | (A And B) results = False (A And A) results = True |

Or | The Or Operator verifies and returns a true value, if anyone operand is true from both the operands. | (A Or B), result = True |

Not | The Not Operator reverses the logical condition such as if the operand’s logic is True then it reveres the condition and makes it false and its vice-versa. | Not A Or Not(A And B), result = True |

Xor | It is an Exclusive OR Operator that verifies, whether both the expression is true or false, the result is True; otherwise, the result is False. | A XOR B is True |

AndAlso | It is a logical AND Operator that performs short-circuit operation on the variables, and if both the operands are true, the result is True else the result is False. | A AndAlso B = False |

OrElse | It is a logical OR Operator that perform short-circuit operation on Boolean data. If anyone of the operand is true, the result is True else the result is False. | A OrElse B = True |

IsFalse | The IsFalse Operator is used to determine that an expression is False. | |

IsTrue | The IsTrue Operator is used to determine that an expression is True. |

#### Bitwise Operator

Operator Symbols | Description | Example |

AND | The Binary AND Operator are used to copy the common binary bit in the result if the bit exists in both operands. | |

OR | The Binary OR Operator is used to copy a common binary bit in the result if the bit found in either operand. | |

XOR | The Binary XOR Operator in VB.NET is used to determine whether a bit is available to copy in one operand instead of both. | |

Not | The binary NOT Operator is also known as the binary Ones’ Compliment Operator, which is used to flip binary bits. This means it converts the bits from 0 to 1 or 1 to 0 binary bits. | |

<< [Left Shift] | The Binary Left Shift Operator is used to shift the bit to the left side in their structure. | |

>> [Right Shift] | The Binary Right Shift Operator is used to shift the bit to the right side in their structure. |

#### Assignment Operator

Operator | Description | Example |

= | It is a simple Assignment Operator used to assign a right-side operand or value to a left side operand. | X = 7, here X assigns a value 7. X = P + Q, here (P + Q) variables or value assign to X. |

+= | It is an Add and Assignment Operator that is used to add the value of the right operands first and then finally assigns to the left operand. | X += 7, which is equivalent to X= X+7 (i.e., 7 is added and assign to X and then result saved to Left X operand finally) |

-= | It is a Subtract and Assignment Operator, which subtracts the right-side operands or values first and then assigns to the left operand finally. | X -= 10, which is equivalent to X = X – 10 |

*= | It is a Multiply and Assignment Operator, which multiplies the right-side operands or values first and then assign to the left operand finally. | X *= Y, which is equivalent as X = X * Y |

/= | It is an Integer Divide and Assignment Operator, which divides the right operands or values first and then, the result is assigned to the left operand finally. | X /= Y, which is equivalent as X = X/ Y |

\= | It is a Floating- Point Divide and Assignment Operator, which divides the right-side operands or values and then the result is finally assigned to the left side operand. | X \= Y, which is same as X = X \ Y |

^= | It is an Exponent and Assignment Operator, which calculates the right-side operands or values as power or exponent and then, the result is finally assigned to the left operand. | X ^= Y, which is same as X = X ^ Y |

&= | It is a Concatenate String Assignment Operator which is used to bind/concatenate the right-side strings or variables and then, the result is assigned finally to the left operand. | Str &= name, which is equivalent as Str = Str & name |

#### Concatenation Operator

Operator | Description | Example |

& | This symbol is used to bind two or more operands together. Using this, a non-string operand can also be concatenated/bind with a string variable (when Option Strict is on). | Str= Wel & come, Str= Welcome |

+ | This symbol is also used to add or concatenate two number or strings. | Str= Wel + come, Str= Welcome |

#### Miscellaneous Operator

Name of Operators | Description | Example |

Await | This operator is used in an operand to suspend the execution of an asynchronous method or lambda expression until the awaited task completes. | Dim output as out = Await AsyncMethodThatReturnsResult() Await AsyncMethod() |

AddressOf | The AddressOf Operator is used to provide a reference to the address of a procedure. | AddHandler Button1.Click, AddressOf Button1_Click |

GetType | This operator is used to retrieve the data type of the specified object. In addition, the retrieved object type provides various information such as methods, properties, and events. | MsgBox(GetType(String).ToString()) |

Function Expression | It defines the lambda expression, which declares the parameter and code. [A Lambda expression is a function that is used to calculate and return value without defining the name.] | Dim mult = Function(num As Integer) num * 4 Console.WriteLine(mult(4)) |

## Order of Precedence in VB .Net Operators

- Operator precedence determines the order in which different Operators in a complex expression are evaluated.
- There are different and distinct levels of precedence of operators.
- In the Operator Precedence table, the operators occupy at a higher level of precedence are evaluated first. But operators having similar precedents in same levels are evaluated at either from left-to-right or right-to-left direction following associativity rules.

Name of Operations | Operator Symbols | Order of Precedence |

Await | Highest | |

Exponential | ^ | ↓ |

Unary identity and negation | +, – | ↓ |

Multiplication and floating-point division | *, / | ↓ |

Integer division | \ | ↓ |

Modulus division | Mod | ↓ |

Addition and Subtraction | +, – | ↓ |

Arithmetic bit shift | <<, >> | ↓ |

All comparison Operators | =, <>, <, <=, >, >=, Is, IsNot, Like, TypeOf …is | ↓ |

Negation | Not | ↓ |

Conjunction | And, AndAlso | ↓ |

Inclusive disjunction | Or, Else | ↓ |

Exclusive disjunction | Xor | Lowest |

## 0 Comments