课程表

VB.Net基本教程

VB.Net高级教程

工具箱
速查手册

VB.Net - 赋值运算符

当前位置:免费教程 » 程序设计 » VB.Net

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

运算符描述示例
=Simple 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 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 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 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 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 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 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 assignment operator
左移AND赋值运算符
C <<= 2 is same as C = C << 2
>>=Right shift AND 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中可用的所有赋值运算符:
  1. Module assignment
  2. Sub Main()
  3. Dim a As Integer = 21
  4. Dim pow As Integer = 2
  5. Dim str1 As String = "Hello! "
  6. Dim str2 As String = "VB Programmers"
  7. Dim c As Integer
  8. c = a
  9. Console.WriteLine("Line 1 - = Operator Example, _
  10. Value of c = {0}", c)
  11. c += a
  12. Console.WriteLine("Line 2 - += Operator Example, _
  13. Value of c = {0}", c)
  14. c -= a
  15. Console.WriteLine("Line 3 - -= Operator Example, _
  16. Value of c = {0}", c)
  17. c *= a
  18. Console.WriteLine("Line 4 - *= Operator Example, _
  19. Value of c = {0}", c)
  20. c /= a
  21. Console.WriteLine("Line 5 - /= Operator Example, _
  22. Value of c = {0}", c)
  23. c = 20
  24. c ^= pow
  25. Console.WriteLine("Line 6 - ^= Operator Example, _
  26. Value of c = {0}", c)
  27. c <<= 2
  28. Console.WriteLine("Line 7 - <<= Operator Example,_
  29. Value of c = {0}", c)
  30. c >>= 2
  31. Console.WriteLine("Line 8 - >>= Operator Example,_
  32. Value of c = {0}", c)
  33. str1 &= str2
  34. Console.WriteLine("Line 9 - &= Operator Example,_
  35. Value of str1 = {0}", str1)
  36. Console.ReadLine()
  37. End Sub
  38. End Module

当上述代码被编译和执行时,它产生以下结果:
  1. Line 1 - = Operator Example, Value of c = 21
  2. Line 2 - += Operator Example, Value of c = 42
  3. Line 3 - -= Operator Example, Value of c = 21
  4. Line 4 - *= Operator Example, Value of c = 441
  5. Line 5 - /= Operator Example, Value of c = 21
  6. Line 6 - ^= Operator Example, Value of c = 400
  7. Line 7 - <<= Operator Example, Value of c = 1600
  8. Line 8 - >>= Operator Example, Value of c = 400
  9. Line 9 - &= Operator Example, Value of str1 = Hello! VB Programmers
转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号