当前位置: 首页 > 文档资料 > VB.Net 中文教程 >

Show 例子 1

优质
小牛编辑
127浏览
2023-12-01

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

操作者描述
^将一个操作数提升到另一个操作数B ^ A将给49
+添加两个操作数A + B将给出9
-从第一个减去第二个操作数A - B将给-5
*将两个操作数相乘A * B将给出14
/将一个操作数除以另一个操作数并返回浮点结果B/A将给出3.5
\将一个操作数除以另一个操作数并返回整数结果B\A将给出3
MOD模数运算符和整数除法后的余数B MOD A将给出1

例子 (Example)

尝试以下示例来了解VB.Net中可用的所有算术运算符 -

Module operators
   Sub Main()
      Dim a As Integer = 21
      Dim b As Integer = 10
      Dim p As Integer = 2
      Dim c As Integer
      Dim d As Single
      c = a + b
      Console.WriteLine("Line 1 - Value of c is {0}", c)
      c = a - b
      Console.WriteLine("Line 2 - Value of c is {0}", c)
      c = a * b
      Console.WriteLine("Line 3 - Value of c is {0}", c)
      d = a/b
      Console.WriteLine("Line 4 - Value of d is {0}", d)
      c = a\b
      Console.WriteLine("Line 5 - Value of c is {0}", c)
      c = a Mod b
      Console.WriteLine("Line 6 - Value of c is {0}", c)
      c = b ^ p
      Console.WriteLine("Line 7 - Value of c is {0}", c)
      Console.ReadLine()
   End Sub
End Module

编译并执行上述代码时,会产生以下结果 -

Line 1 - Value of c is 31
Line 2 - Value of c is 11
Line 3 - Value of c is 210
Line 4 - Value of d is 2.1
Line 5 - Value of c is 2
Line 6 - Value of c is 1
Line 7 - Value of c is 100