课程表

VB.Net基本教程

VB.Net高级教程

工具箱
速查手册

VB.Net - 算术运算符

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

下表显示了VB.Net支持的所有算术运算符。 假设变量A保持2,变量B保持7,则:

运算符描述示例
^Raises one operand to the power of another
将一个操作数提升为另一个的权力
B^A will give 49
+Adds two operands
添加两个操作数
A + B will give 9
-Subtracts second operand from the first
从第一个操作数中减去第二个操作数
A - B will give -5
*Multiplies both operands
将两个操作数相乘
A * B will give 14
/Divides one operand by another and returns a floating point result
将一个操作数除以另一个操作数,并返回一个浮点结果
B / A will give 3.5
\Divides one operand by another and returns an integer result
将一个操作数除以另一个操作数,并返回一个整数结果
B \ A will give 3
MODModulus Operator and remainder of after an integer division
模数运算符和整数除法后的余数
B MOD A will give 1

示例:

请尝试下面示例了解所有可用在 VB.Net 算术运算符
  1. Module operators
  2. Sub Main()
  3. Dim a As Integer = 21
  4. Dim b As Integer = 10
  5. Dim p As Integer = 2
  6. Dim c As Integer
  7. Dim d As Single
  8. c = a + b
  9. Console.WriteLine("Line 1 - Value of c is {0}", c)
  10. c = a - b
  11. Console.WriteLine("Line 2 - Value of c is {0}", c)
  12. c = a * b
  13. Console.WriteLine("Line 3 - Value of c is {0}", c)
  14. d = a / b
  15. Console.WriteLine("Line 4 - Value of d is {0}", d)
  16. c = a \ b
  17. Console.WriteLine("Line 5 - Value of c is {0}", c)
  18. c = a Mod b
  19. Console.WriteLine("Line 6 - Value of c is {0}", c)
  20. c = b ^ p
  21. Console.WriteLine("Line 7 - Value of c is {0}", c)
  22. Console.ReadLine()
  23. End Sub
  24. End Module

当上述代码被编译和执行时,它产生以下结果:
  1. Line 1 - Value of c is 31
  2. Line 2 - Value of c is 11
  3. Line 3 - Value of c is 210
  4. Line 4 - Value of d is 2.1
  5. Line 5 - Value of c is 2
  6. Line 6 - Value of c is 1
  7. Line 7 - Value of c is 100
转载本站内容时,请务必注明来自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号