An operator is a symbol that indicates which operations are performed, to the compiler. An operation has basically two parts: operator and operands.
For example in the given operation,
a + b
The variables a and b are called operands and the symbol + is called the operator.
In Visual Basic .Net there are mainly six type of operators they are given below.
- Arithmetic Operators
- Comparison Operators
- Logical/ Bitwise Operators
- Bit Shift Operators
- Assignment Operators
- Miscellaneous Operators
The arithmetic operators supported by VB.Net are seven in number.
- Performs the basic addition of the mathematics.
- Uses the + symbol.
- Eg: a + b
- Performs the basic subtraction of mathematics.
- Uses the – symbol.
- Eg: a – b
- Performs the basic multiplication of the mathematics.
- Uses the * symbol.
- Eg: a * b
- Performs the basic division of the mathematics.
- Uses the / symbol.
- Eg: a / b
- Performs the integer division which avoids the decimal point in the result.
- Uses the \ symbol.
- Eg: a\b
- Used to find the modulus of a division operation.
- Uses the keyword Mod or the symbol %.
- Eg: a Mod b or a % b
- Used to find the power of an operand by another operand.
- Uses the symbol ^.
- Eg: 2^3 calculates the 3rd power of 2, which is 8.
The VB.Net supports the following relational operators.
- Less than: uses the symbol <, example: a<b
- Less than or equal to: uses the symbol <=, example: a<=b
- Greater than: uses the symbol >, example: a>b
- Greater than or equal to: uses the symbol >=, example: a>=b
- Equal To: uses the symbol ==, example: a==b
- Not Equal To: uses the symbol <>, example: a<>b
- Is: compares the references.
- IsNot: compares the references, but the results will be opposite of Is.
- Like: It compares a string against a pattern.
Logical/Bitwise Operators (Boolean Operators)
These are the logical operators supported by Visual Basic .Net.
- And: (A And B) is False.
- Or: (A Or B) is True.
- Note: Not(A And B) is True.
- Xor: A Xor B is True.
- AndAlso: (A AndAlso B) is False.
- OrElse: (A OrElse B) is True.
Bitwise operators are used to works with bits of a binary number.
- Not: bitwise negation
- Xor: bitwise exclusive or
- And: bitwise and
- Or: bitwise or
The VB.Net supports the following assignment operators.
- ( = ) Simple assignment operator
- ( += ) Add AND assignment operator
- ( -= ) Subtract AND assignment operator
- ( *= ) Multiply AND assignment operator
- ( /= ) Divide AND assignment operator
- ( \= ) Divide AND assignment operator
- ( ^= ) Exponentiation and assignment operator
- ( <<= ) Left shift AND assignment operator
- ( >>= ) Right shift AND assignment operator
- ( &= ) Concatenates a String expression to a String variable
The following are the Visual Basic miscellaneous operators.
- AddressOf : Returns the address of a procedure.
- Await : Is applied to a task in an asynchronous method to suspend the execution of the method until the awaited task completes.
- GetType : It returns a Type object for the specified type.
- Function Expression : It declares the parameters and code that define a function lambda expression.
- If : It uses short-circuit evaluation to conditionally return one of two values.