×

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支持的所有比较运算符。 假设变量A保持10,变量B保持20,则:

运算符 描述 示例
= Checks if the values of two operands are equal or not; if yes, then condition becomes true.
检查两个操作数的值是否相等; 如果是,则条件变为真。
(A = B) is not true.
<> Checks if the values of two operands are equal or not; if values are not equal, then condition becomes true.
检查两个操作数的值是否相等; 如果值不相等,则条件为真。
(A <> B) is true.
> Checks if the value of left operand is greater than the value of right operand; if yes, then condition becomes true.
检查左操作数的值是否大于右操作数的值; 如果是,则条件变为真。
(A > B) is not true.
< Checks if the value of left operand is less than the value of right operand; if yes, then condition becomes true.
检查左操作数的值是否小于右操作数的值; 如果是,则条件变为真。
(A < B) is true.
>= Checks if the value of left operand is greater than or equal to the value of right operand; if yes, then condition becomes true.
检查左操作数的值是否大于或等于右操作数的值; 如果是,则条件变为真。
(A >= B) is not true.
<= Checks if the value of left operand is less than or equal to the value of right operand; if yes, then condition becomes true.
检查左操作数的值是否小于或等于右操作数的值; 如果是,则条件变为真。
(A <= B) is true.

尝试以下示例来了解VB.Net中提供的所有关系运算符:

Module operators
   Sub Main()
      Dim a As Integer = 21
      Dim b As Integer = 10
      If (a = b) Then
          Console.WriteLine("Line 1 - a is equal to b")
      Else
          Console.WriteLine("Line 1 - a is not equal to b")
      End If
      If (a < b) Then
          Console.WriteLine("Line 2 - a is less than b")
      Else
          Console.WriteLine("Line 2 - a is not less than b")
      End If
      If (a > b) Then
          Console.WriteLine("Line 3 - a is greater than b")
      Else
          Console.WriteLine("Line 3 - a is not greater than b")
      End If
      ' Lets change value of a and b 
      a = 5
      b = 20
      If (a <= b) Then
          Console.WriteLine("Line 4 - a is either less than or equal to  b")
      End If
      If (b >= a) Then
          Console.WriteLine("Line 5 - b is either greater than  or equal to b")
      End If
      Console.ReadLine()
   End Sub
End Module

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

Line 1 - a is not equal to b
Line 2 - a is not less than b
Line 3 - a is greater than b
Line 4 - a is either less than or equal to b
Line 5 - b is either greater than or equal to b

除了上述,VB.Net提供了三个比较运算符,我们将在以后的章节中使用; 不过,我们在这里给出一个简短的描述。

1、Is 运算符 -它比较两个对象引用变量,并确定两个对象引用是否引用相同的对象,而不执行值比较。 如果object1和object2都引用完全相同的对象实例,则result为True; 否则,result为False。

2、IsNott 运算符 - 它还比较两个对象引用变量,并确定两个对象引用是否引用不同的对象。 如果object1和object2都引用完全相同的对象实例,则result为False; 否则,result为True。

3、Like 运算符 - 它将字符串与模式进行比较。



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


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)