• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
 
Microsoft Visual Basic .Net 
Operators Listed by Functionality
S.#OperatorsDescription
1Arithmetic
These operators perform mathematical calculations.
2Assignment
These operators perform assignment operations.
3Co
 
mparison
These operators perform comparisons.
4Concatenation
These operators combine strings.
5Logical/Bitwise
These operators perform logical operations.
6Bit Shift
These operators perform arithmetic shifts on bit patterns.
1.Arithmetic Operators
The following are the arithmetic operators defined in Visual Basic .NET.
S.#OperatorsDescription
1^
(Number ^ exponent)Raises a number to the power of another number.
2*
(Number1 * Number2)Multiplies two numbers.
3/
(Number1 / Number2)Divides two numbers and returns quotient in floating-point result.
4\
(Number1 \ Number2)Divides two numbers and returns quotient in integer result.
5Mod
(Number1 Mod Number2)Divides two numbers and returns only the remainder.
6
+ (
expression1
+ expression2)Adds two numbers. Also used to concatenate two strings.
7-
(
expression1
- expression2)subtraction operator for the difference between two numbers.
Examples Of (Arithmetic Operators)
Module Module1Sub Main()Console.WriteLine(2 ^ 2)4Console.WriteLine(3 ^ 3 ^ 3)19683Console.WriteLine((-5) ^ 2)25(According Mathematic rule Even for +)Console.WriteLine((-5) ^ 9)‘-1953125 (According Mathematic rule odd for -)Console.WriteLine()Console.WriteLine(10 * 4)40Console.WriteLine()Console.WriteLine(10 / 4)2.5Console.WriteLine(10 \ 4)2Console.WriteLine()Console.WriteLine(10 Mod 5)0Console.WriteLine(10 Mod 3)1Console.WriteLine(12 Mod 4.3)3.4Console.WriteLine()Console.WriteLine(10 + 4)14Console.WriteLine(10 - 4)6Console.ReadLine()End SubEnd Module
1 of 7
 
Microsoft Visual Basic .Net 
2.Assignment Operators
The following are the Assignment operators defined in Visual Basic .NET.
S.#OperatorsDescription
1
= (var=value)Used to assign a value to a variable or property.
2^=
(var ^= expression)Raises the value of a variable to the power of an expression and assigns theresult back to the variable.
3*=
(var *= expression)Multiplies the value of a variable by the value of an expression and assignsthe result to the variable.
4/=
(var /= expression)Divides the value of a variable by the value of an expression and assigns thefloating-point result to the variable.
5\=
(var \= expression)Divides the value of a variable by the value of an expression and assigns theinteger result to the variable.
6
+=(var += expression)Adds the value of an expression to the value of a variable and assigns theresult to the variable. Also concatenates a
String
expression to a
String
variable and assigns the result to the variable.
7-=
(var -= expression)Subtracts the value of an expression from the value of a variable and assignsthe result to the variable.
8<<=(var >>=amount)Performs an arithmetic left shift on the value of a variable and assignsthe result back to the variable.9>>=(var >>=amount)Performs an arithmetic right shift on the value of a variable andassigns the result back to the variable.10
&= (var &= expression)Concatenates a
String
expression to a
String
variable and assigns the resultto the variable.
Examples Of (
Assignment
Operators)
Module Module1Sub Main()Dim var As IntegerDim var1 As String = "Hello" : Dim var2 As String = "Dear"var = 5Console.WriteLine(var)5var ^= 3Console.WriteLine(var)125var *= 3Console.WriteLine(var)375var /= 3Console.WriteLine(var)125var \= 3Console.WriteLine(var)41var += 3Console.WriteLine(var)44var -= 3Console.WriteLine(var)41
var <<= 3Console.WriteLine(var)328var >>= 3Console.WriteLine(var)41
var &= 3Console.WriteLine(var)413Console.WriteLine(var1)HelloConsole.WriteLine(var2)Dearvar1 &= var2Console.WriteLine(var1)HelloDearConsole.ReadLine()
2 of 7
 
Microsoft Visual Basic .Net 
End SubEnd Module
3.Comparison Operators
Compares expressions.
S.#OperatorTrue ifFalse i1<
(Less than)
expression1
<
expression2 expression1
>=
expression2
2<=
(Less than or equal to)
expression1
<=
expression2 expression1
>
expression2
3>
(Greater than)
expression1
>
expression2 expression1
<=
expression2
4>=
(Greater than or equal to)
expression1
>=
expression2 expression1
<
expression2
5=
(Equal to)
expression1
=
expression2 expression1
<>
expression2
6<>
(Not
 
equal to)
expression1
<>
expression2 expression1
=
expression2
7Is
and
Like
Have specific comparison functionality that differs from above operators
Examples Of (Comparison Operators)
Module Module1Sub Main()Console.WriteLine(30 < 35)TConsole.WriteLine(40 < 35)FConsole.WriteLine(30 <= 30)TConsole.WriteLine(30 <= 25)FConsole.WriteLine(35 > 30)TConsole.WriteLine(35 > 45)FConsole.WriteLine(30 >= 35)FConsole.WriteLine(30 = 30)TConsole.WriteLine(30 = 35)FConsole.WriteLine(30 <> 35)TConsole.ReadLine()End SubEnd Module
4.Concatenation OperatorsS.#OperatorsDescription
1
 
& (expression1 & expression2)Generates a string concatenation of two expressions.
2+
(expression1 + expression2)Adds two numbers. Also used to concatenate two strings.
Note for + Concatenation Operator
S.#
IfThen1
Both expressions are numericAdd.
2
Both expressions are stringsConcatenate.
3
One expression is numeric and theother is a stringImplicitly cast the numeric expression to
Double
and add. If expression
 
cannot be converted to a numeric value, an
InvalidCastException
is thrown.
Examples Of (Concatenation Operators)
Module Module1Sub Main()Dim intvar1 As Integer = 10Dim intvar2 As Integer = 20Dim strvar1 As String = "Hello"Dim strvar2 As String = "Dear"Console.WriteLine(intvar1 & intvar2)‘1020Console.WriteLine(strvar1 & strvar2)‘HelloDearConsole.WriteLine(intvar1 & strvar1)‘10HelloConsole.WriteLine(intvar1 + intvar2)‘30
3 of 7
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...