×

VB.Net基本教程

VB.Net 环境设置VB.Net 程序结构VB.Net 基本语法VB.Net 数据类型VB.Net 变量VB.Net 常数和枚举VB.Net 修饰符VB.Net 声明VB.Net 指令VB.Net 运算符VB.Net 决策VB.Net 循环VB.Net 字符串VB.Net 日期和时间VB.Net 数组VB.Net 集合VB.Net 函数VB.Net Sub过程(子程序)VB.Net 类与对象VB.Net 异常处理VB.Net 文件处理VB.Net 基本控制VB.Net 对话框VB.Net 高级表单VB.Net 事件处理

VB.Net 高级教程

VB.Net 正则表达式VB.Net 数据库访问VB.Net Excel工作表VB.Net 发送邮件VB.Net XML处理VB.Net Web编程

VB.Net 有用的资源

VB.Net 有用资源

VB.Net 赋值运算符


VB.Net  运算符VB.Net 运算符


VB.Net支持以下赋值运算符:

运算符 描述 示例
= Simple vbnet-assignment operator, Assigns values from right side operands to left side operand
简单赋值操作符,将值从右侧操作数分配给左侧操作数
C = A + B will assign value of A + B into C
+= Add AND vbnet-assignment operator, It adds right operand to the left operand and assigns the result to left operand
添加AND赋值运算符,向左操作数添加右操作数,并将结果赋给左操作数
C += A is equivalent to C = C + A
-= Subtract AND vbnet-assignment operator, It subtracts right operand from the left operand and assigns the result to left operand
减法AND赋值运算符,它从左操作数中减去右操作数,并将结果赋给左操作数
C -= A is equivalent to C = C - A
*= Multiply AND vbnet-assignment operator, It multiplies right operand with the left operand and assigns the result to left operand
乘法AND赋值运算符,它将右操作数与左操作数相乘,并将结果赋给左操作数
C *= A is equivalent to C = C * A
/= Divide AND vbnet-assignment operator, It divides left operand with the right operand and assigns the result to left operand (floating point division)
除法AND赋值运算符,它用右操作数划分左操作数,并将结果分配给左操作数(浮点除法)
C /= A is equivalent to C = C / A
= Divide AND vbnet-assignment operator, It divides left operand with the right operand and assigns the result to left operand (Integer division)
除法AND赋值运算符,它用右操作数划分左操作数,并将结果分配给左操作数(整数除法)
C = A is equivalent to C = C A
^= Exponentiation and vbnet-assignment operator. It raises the left operand to the power of the right operand and assigns the result to left operand
指数和赋值运算符。 它将左操作数提升为右操作数的幂,并将结果分配给左操作数
C^=A is equivalent to C = C ^ A
<<= Left shift AND vbnet-assignment operator
左移AND赋值运算符
C <<= 2 is same as C = C << 2
>>= Right shift AND vbnet-assignment operator
右移AND赋值运算符
C >>= 2 is same as C = C >> 2
&= Concatenates a String expression to a String variable or property and assigns the result to the variable or property.
将String表达式连接到String变量或属性,并将结果分配给变量或属性。

Str1 &= Str2 is same as

Str1 = Str1 & Str2


示例:

尝试以下示例来了解VB.Net中可用的所有赋值运算符:
Module vbnet-assignment
   Sub Main()
      Dim a As Integer = 21
      Dim pow As Integer = 2
      Dim str1 As String = "Hello! "
      Dim str2 As String = "VB Programmers"
      Dim c As Integer
      c = a
      Console.WriteLine("Line 1 - =  Operator Example, _
	  Value of c = {0}", c)
      c += a
      Console.WriteLine("Line 2 - +=  Operator Example, _
	  Value of c = {0}", c)
      c -= a
      Console.WriteLine("Line 3 - -=  Operator Example, _
	  Value of c = {0}", c)
      c *= a
      Console.WriteLine("Line 4 - *=  Operator Example, _
	  Value of c = {0}", c)
      c /= a
      Console.WriteLine("Line 5 - /=  Operator Example, _
	  Value of c = {0}", c)
      c = 20
      c ^= pow
      Console.WriteLine("Line 6 - ^=  Operator Example, _
	  Value of c = {0}", c)
      c <<= 2
      Console.WriteLine("Line 7 - <<=  Operator Example,_
	  Value of c = {0}", c)
      c >>= 2
      Console.WriteLine("Line 8 - >>=  Operator Example,_
	  Value of c = {0}", c)
      str1 &= str2
      Console.WriteLine("Line 9 - &=  Operator Example,_
	  Value of str1 = {0}", str1)
      Console.ReadLine()
   End Sub
End Module

当上述代码被编译和执行时,它产生以下结果:
Line 1 - =  Operator Example, Value of c = 21
Line 2 - += Operator Example, Value of c = 42
Line 3 - -= Operator Example, Value of c = 21
Line 4 - *= Operator Example, Value of c = 441
Line 5 - /= Operator Example, Value of c = 21
Line 6 - ^= Operator Example, Value of c = 400
Line 7 - <<= Operator Example, Value of c = 1600
Line 8 - >>= Operator Example, Value of c = 400
Line 9 - &= Operator Example, Value of str1 = Hello! VB Programmers


VB.Net  运算符VB.Net 运算符


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)