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
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:
Dim a as integer, b as integer, c as integer
a = 5
b = 2
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 returns 2 |
^
|
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
It returns 32 |
Mod
|
It performs arithmetic
division of two operands and returns the remainder of the division as result.
|
C = A Mod
B
It returns 1 |
|
|
|
(2) Comparison Operator
Following are the list
of Comparison operators supported by VB.NET:
Suppose we declare two variables:
Suppose we declare two variables:
Dim a as integer, b as integer
a = 5
b = 2
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 returns FALSE |
>
|
It compares two
operands and returns TRUE if Operand1 is greater then Operand2 otherwise it
returns FALSE.
|
A > B
It returns TRUE |
<=
|
It compares two
operands and returns TRUE if Operand1 is less then or equal to Operand2
otherwise it returns FALSE.
|
A <= B
It returns FALSE |
>=
|
It compares two
operands and returns TRUE if Operand1 is greater then or equal to Operand2
otherwise it returns FALSE.
|
A >= B
It returns TRUE |
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:
* 0 or more occurrence of any characters ? single character # single digit [Character List] single character in the range.
[! CharacterList]
single character not in the range.
|
Dim a as
string=”Hello”
a Like “H*” returns true.
a Like “H?” returns
false.
|
(3)String Concatenation Operator
Following are the list
of concatenation operators supported by VB.NET.
Consider Following Example:
Consider Following Example:
Dim a as string, b as string, c as string
Dim d as integer, e as integer, f as integer
a = “Hello”
b = “How Are You”
d = 2
e = 3
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 returns Hello How Are You f = d + e It returns 23 |
+
|
It Concate two
operands or string.
If both the operand are numeric then instead of concating them it will produce addition of operands. |
c = a + b
It returns Hello How Are You f = d + e It returns 5 |
(4) Logical Operator
Following are the list
of Logical Operators supported by VB.NET:
Consider Following Example:
Consider Following Example:
Dim a as Boolean, b as Boolean, c as Boolean
a = true
b = false
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
It returns false |
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
It returns false |
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)
It returns true |
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
It return true. |
AndAlso
|
It works same as AND operator
but It will not evaluate second operand if first operand is FALSE.
|
c = a AndAlso b
It returns false. |
OrElse
|
It works same as OR
operator but It will not evaluate second operand if first operand is TRUE.
|
c = a OrElse b
It returns true. |
(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
can be written as a+=b |
-=
|
Subtract right operand
from left operand and assign result to left operand.
|
a = a - b
can be written as a-=b |
*=
|
Multiply right operand
with left operand and assign result to left operand.
|
a = a * b
can be written as a*=b |
/=
|
Divide left operand by
right operand and assign result to left operand.
|
a = a / b
can be written as a/=b |
\=
|
Divide left operand by
right operand and assign result to left operand.
|
a = a \ b
can be written as a\=b |
^=
|
Raise left operand to
the power of right operand and assign result to left operand.
|
a = a ^ b
can be written as a^=b |
&=
|
Concate left operand
with right operand and assign result to left operand.
|
a = a & b
can be written as a&=b |
Comments
Post a Comment