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
Leave a Comment