×

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 运算符


运算符优先级确定表达式中的术语分组。 这会影响表达式的计算方式。 某些运营商比其他运营商具有更高的优先级; 例如,乘法运算符的优先级高于加法运算符:

例如,x = 7 + 3 * 2; 这里,x被分配13,而不是20,因为operator *具有比+高的优先级,因此它首先乘以3 * 2,然后加到7。

这里,具有最高优先级的运算符出现在表的顶部,具有最低优先级的运算符出现在底部。 在表达式中,将首先计算较高优先级运算符。

操作符 优先级
Await 最高
Exponentiation (^)  
Unary identity and negation (+, -)  
Multiplication and floating-point division (*, /)  
Integer division ()  
Modulus arithmetic (Mod)  
Addition and subtraction (+, -)  
Arithmetic bit shift (<<, >>)  
All comparison operators (=, <>, <, <=, >, >=, Is, IsNot, Like, TypeOf...Is)  
Negation (Not)  
Conjunction (And, AndAlso)  
Inclusive disjunction (Or, OrElse)  
Exclusive disjunction (Xor) 最低

示例:

以下示例以简单的方式演示运算符优先级:

Module assignment
   Sub Main()
      Dim a As Integer = 20
      Dim b As Integer = 10
      Dim c As Integer = 15
      Dim d As Integer = 5
      Dim e As Integer
      e = (a + b) * c / d      ' ( 30 * 15 ) / 5
      Console.WriteLine("Value of (a + b) * c / d is : {0}", e)
      e = ((a + b) * c) / d    ' (30 * 15 ) / 5
      Console.WriteLine("Value of ((a + b) * c) / d is  : {0}", e)
      e = (a + b) * (c / d)   ' (30) * (15/5)
      Console.WriteLine("Value of (a + b) * (c / d) is  : {0}", e)
      e = a + (b * c) / d     '  20 + (150/5)
      Console.WriteLine("Value of a + (b * c) / d is  : {0}", e)
      Console.ReadLine()
   End Sub
End Module

当上述代码被编译和执行时,它产生以下结果:

Value of (a + b) * c / d is : 90
Value of ((a + b) * c) / d is  : 90
Value of (a + b) * (c / d) is  : 90
Value of a + (b * c) / d is  : 50

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


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)