May 13, 2021 vb.net
An operator is a symbol that tells the compiler to perform specific mathematical or logical operations. V b. N et is rich in built-in operators and provides the following types of common operators:
Arithmetic operator
Comparison operator
Logic/bit operator
The displacement operator
The assignment operator
Other operators
This tutorial will cover the most commonly used operators.
The following table shows VB.Net arithmetic operators that are supported by the system. A ssuming variable A remains 2 and variable B remains 7, then:
Operator | Describe | Cases |
---|---|---|
^ |
Raises one operand to the power of anothe Use one operast as a power for another |
B^A will give 49 |
+ |
Adds two operand Add two operans s |
A + B will give 9 |
- |
Subtracts second operand from the first
Subtract the second operand from the first operand |
A - B will give -5 |
* |
Multiplies both operand s Multiply the two operations |
A * B will give 14 |
/ |
Divides one operand by another and returns a floating point result
Divide one operation by another and return a floating-point result |
B / A will give 3.5 |
\ |
Divides one operand by another and returns an integer result
Divide one operation by another and return an integer result |
B \ A will give 3 |
MOD |
Modulus Operator and remainder of after an integer division
The remaining number after the module operator and the integer division |
B MOD A will give 1 |
The following table shows VB.Net the comparison operators that are supported by the system. A ssuming variable A remains at 10 and variable B remains at 20, then:
Operator | Describe | Cases |
---|---|---|
= |
Checks if the values of two operands are equal or not;
if yes, then condition becomes true.
Check that the values of the two operasts are equal; If so, the condition becomes true. |
(A s B) is incorrect. |
<>
|
Checks if the values of two operands are equal or not; if values are not equal, then condition becomes true.
Check that the values of the two operasts are equal;
If the values are not equal, the condition is true.
|
(A-lt;b) is true. |
> |
Checks if the value of left operand is greater than the value of right operand;
if yes, then condition becomes true.
Check whether the value of the left operanzo is greater than the value of the right operans; If so, the condition becomes true. |
This is incorrect. |
< |
Checks if the value of left operand is less than the value of right operand;
if yes, then condition becomes true.
Check whether the value of the left operanzo is less than the value of the right operans; If so, the condition becomes true. |
(A -lt;B) is true. |
> = |
Checks if the value of left operand is greater than or equal to the value of right operand;
if yes, then condition becomes true.
Check whether the value of the left operanzo is greater than or equal to the value of the right operans; If so, the condition becomes true. |
It is incorrect. |
<= |
Checks if the value of left operand is less than or equal to the value of right operand;
if yes, then condition becomes true.
Check whether the value of the left operanzo is less than or equal to the value of the right operans; If so, the condition becomes true. |
(A -lt;?B) is true. |
In addition to the above, VB. N
et provides three comparison operators, which we'll use in a later section;
However, here we give a brief description.
1,
Is operator
- It compares two object reference variables and determines whether two object references reference the same object without performing a value comparison. T
rue if both object 1 and object2 refer to identical object instances;
Otherwise, the result is False.
2,
IsNot operator
- It also compares two object reference variables and determines whether two object references refer to different objects. I
f both object 1 and object2 refer to identical object instances, the result is False;
Otherwise, the result is True.
3,
Like operator - It
compares strings to patterns.
The following table shows VB.Net logical operators that are supported by the system. A ssuming that variable A keeps the Boolean value True and variable B keeps the Boolean value False, then:
Operator | Describe | Cases |
---|---|---|
And |
It is the logical as well as bitwise AND operator. I
f both the operands are true, then condition becomes true.
This operator does not perform short-circuiting, i.e., it evaluates both the expressions.
It is logic as well as bit-by-bit AND operators. I f both operations are true, the condition is true. This operator does not short-circuit, that is, it evaluates two expressions. |
(A and B) are false. |
Or |
It is the logical as well as bitwise OR operator. I
f any of the two operands is true, then condition becomes true.
This operator does not perform short-circuiting, i.e., it evaluates both the expressions.
It is logic as well as bit-by-bit or operator. I f neither of the two operasts is true, the condition is true. This operator does not short-circuit, that is, it evaluates two expressions. |
(A or B) is true. |
Not |
It is the logical as well as bitwise NOT operator. U
se to reverses the logical state of its operand.
If a condition is true, then Logical NOT operator will make false.
It is logical as well as bit-by-bit non-operators. T he logical state used to reverse its operans. If the condition is true, the logical non-operator will be false. |
No (A and B) for true. |
Xor |
It is the logical as well as bitwise Logical Exclusive OR operator. I
t returns True if both expressions are True or both expressions are False; o
therwise it returns False.
This operator does not perform short-circuiting, it always evaluates both expressions and there is no short-circuiting counterpart of this operator.
It is logic as well as bit-by-bit logic or operators. R eturns True if both expressions are True or both expressions are False; O therwise return to False. The operator does not short-circuit, it always evaluates both expressions, and there is no short-circuit correspondence for that operator. |
different or B is true. |
AndAlso |
It is the logical AND operator. I
t works only on Boolean data.
It performs short-circuiting.
It is the logical AND operator. /b17> It applies only to Boolean data. /b114> It performs a short circuit. |
(A AndAlso operation B) is false. |
OrElse |
It is the logical OR operator. I
t works only on Boolean data.
It performs short-circuiting.
It is a logic or operator. I t applies only to Boolean data. It performs a short circuit. |
(A Orelse operation B) is true. |
IsFalse |
It determines whether an expression is False.
It determines whether the expression is false. |
|
IsTrue |
It determines whether an expression is True.
It determines whether the expression is true or not. |
We've discussed bit operators. T
he displacement operator performs a shift operation on the binary value.
Before we get to the displacement operator, let's look at bit operations.
Bit-by-bit operators handle bits and perform bit-by-bit operations.
The true | of the values of the values and the values of the following:
P | Q | p&Q | p | Q | p ^ Q |
---|---|---|---|---|
0 | 0 | 0 | 0 | 0 |
0 | 1 | 0 | 1 | 1 |
1 | 1 | 1 | 1 | 0 |
1 | 0 | 0 | 1 | 1 |
Suppose A is 60; a nd B s 13; N ow in binary format, they will be as follows:
A = 0011 1100
B = 0000 1101
-----------------
A&B = 0000 1100
A | B = 0011 1101
A ^ B = 0011 0001
〜A = 1100 0011
We've VB.Net the Bitwise operators that we support are And, Or, Xor, and Not.
The displacement calculats are used for left and right shifts, respectively.
Assuming variable A remains at 60 and variable B remains at 13, then:
Operator | Describe | Example |
---|---|---|
And |
Bitwise AND Operator copies a bit to the result if it exists in both operands.
If both operastes exist, one bit is copied to the result by bit AND operator. |
(A AND B) will give 12, which is 0000 1100 |
Or |
Binary OR Operator copies a bit if it exists in either operand.
The binary OR operator copies a bit if it exists in either operand. |
(A Or B) will give 61, which is 0011 1101 |
Xor |
Binary XOR Operator copies the bit if it is set in one operand but not both.
The binary XOR operator copies the bit if it is set in one operand, but not two operands. |
(A Xor B) will give 49, which is 0011 0001 |
Not |
Binary Ones Complement Operator is unary and has the effect of 'flipping' bits.
The binary complement operator is binary and has the effect of "flipping" bits. |
(Not A ) will give -61, which is 1100 0011 in 2's complement form due to a signed binary number. |
<< |
Binary Left Shift Operator.
The left operands value is moved left by the number of bits specified by the right operand.
Binary left shift operator. The number of digits specified by the right operans is moved to the left by the left operation value. |
A << 2 will give 240, which is 1111 0000 |
>> |
Binary Right Shift Operator.
The left operands value is moved right by the number of bits specified by the right operand.
Binary right-shift operator. The value of the left operation moves to the right the number of digits specified by the right operans. |
A >> 2 will give 15, which is 0000 1111 |
Operator | Describe | Cases |
---|---|---|
= |
Simple assignment operator, Assigns values from right side operands to left side operand
A simple assignment operator that assigns values from the right-hand operans to the left-hand operans |
C s A s B A s B will be assigned to C |
+ = |
Add AND assignment operator, It adds right operand to the left operand and assigns the result to left operand
Add the AND assignment operator, add the right operans to the left operans, and assign the results to the left operans |
C - A is equal to C - C - A |
- = |
Subtract AND assignment operator, It subtracts right operand from the left operand and assigns the result to left operand
Subtract the AND assignment operator, which subtracts the right operans from the left operans and assigns the result to the left operans |
- - A equals C - C - one |
* = |
Multiply AND assignment operator, It multiplies right operand with the left operand and assigns the result to left operand
Multiplication AND assignment operator, which multiplies the right operans by the left operans and assigns the result to the left operans |
C . . . |
/ = |
Divide AND assignment operator, It divides left operand with the right operand and assigns the result to left operand (floating point division)
Division AND assignment operator, which divides the left operans by the right operans and assigns the results to the left operans (floating-point division) |
C / - A equals C - C / A |
\ = |
Divide AND assignment operator, It divides left operand with the right operand and assigns the result to left operand (Integer division)
Divide the AND assignment operator, which divides the left operans by the right operans and assigns the result to the left operastr (integer division) |
A is equal to C and C A |
^ = |
Exponentiation and assignment operator.
It raises the left operand to the power of the right operand and assigns the result to left operand.
Exponential and assignment operators. It elevates the left operance to the power of the right operans and assigns the results to the left operans. |
C . |
<< = |
Left shift AND assignment operator
Move the AND assignment operator to the left |
The C language is the same as C, and the C is the same as C, and the C is 2 |
>> = |
Right shift AND assignment operator
Move the AND assignment operator to the right |
C |
&= |
Concatenates a String expression to a String variable or property and assigns the result to the variable or property.
Connect the String expression to the String variable or property and assign the result to the variable or property. |
The STR1-STR2 car is the same STR1 - STR1 and STR2 |
There are very few other important operating systems that VB.Net.
Operator | Describe | Cases |
---|---|---|
AddressOf |
Returns the address of a procedure.
Returns the address of the procedure. |
AddHandler Button1.Click, AddressOf Button1_Click |
Await |
It is applied to an operand in an asynchronous method or lambda expression to suspend execution of the method until the awaited task completes.
It applies to the number of operations in an asynchronous method or lambda expression to pause the execution of the method until the waiting task is complete. |
Dim result As res = Await AsyncMethodThatReturnsResult() Await AsyncMethod() |
GetType |
It returns a Type object for the specified type.
The Type object provides information about the type such as its properties, methods, and events.
It returns the type of Type object specified. Type objects provide information about types, such as their properties, methods, and events. |
MsgBox(GetType(Integer).ToString()) |
Function Expression |
It declares the parameters and code that define a function lambda expression.
It declares the parameters and code that define the function lambda expression. |
Dim add5 = Function(num As Integer) num + 5 'prints 10 Console.WriteLine(add5(5)) |
If |
It uses short-circuit evaluation to conditionally return one of two values.
The If operator can be called with three arguments or with two arguments.
It uses a short circuit evaluation to conditionally return one of the two values. You can call the If operator using three or two parameters. |
Dim num = 5 Console.WriteLine(If(num >= 0, "Positive", "Negative")) |
Operators prioritize the grouping of terms in an expression. T
his affects how expressions are evaluated. S
ome operators have a higher priority than others;
For example, the multiplication operator takes precedence over the addition operator:
For example, x s 7 s 3 s 2;
Here, x is assigned 13 instead of 20, because the operator has a higher priority than the plus, so it is first multiplied by 3 x 2, and then added to 7.
Here, the operator with the highest priority appears at the top of the table, and the operator with the lowest priority appears at the bottom.
In an expression, the higher priority operator is evaluated first.
Operator | Priority |
---|---|
Await | Highest |
Exponentiation (^) | |
Unary identity and negation (+, -) | |
Multiplication and floating-point division (*, /) | |
Integer division (\) | |
Modulus arithmetic (Mod) | |
Addition and subtraction (+, -) | |
Arithmetic bit shift (<<, >>) | |
All comparison operators (=, <>, <, <=, >, >=, Is, IsNot, Like, TypeOf... Is) | |
Negation (Not) | |
Conjunction (And, AndAlso) | |
Inclusive disjunction (Or, OrElse) | |
Exclusive disjunction (Xor) | Minimum |