课程表

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中提供的所有关系运算符:

  1. Module operators
  2. Sub Main()
  3. Dim a As Integer = 21
  4. Dim b As Integer = 10
  5. If (a = b) Then
  6. Console.WriteLine("Line 1 - a is equal to b")
  7. Else
  8. Console.WriteLine("Line 1 - a is not equal to b")
  9. End If
  10. If (a < b) Then
  11. Console.WriteLine("Line 2 - a is less than b")
  12. Else
  13. Console.WriteLine("Line 2 - a is not less than b")
  14. End If
  15. If (a > b) Then
  16. Console.WriteLine("Line 3 - a is greater than b")
  17. Else
  18. Console.WriteLine("Line 3 - a is not greater than b")
  19. End If
  20. ' Lets change value of a and b
  21. a = 5
  22. b = 20
  23. If (a <= b) Then
  24. Console.WriteLine("Line 4 - a is either less than or equal to b")
  25. End If
  26. If (b >= a) Then
  27. Console.WriteLine("Line 5 - b is either greater than or equal to b")
  28. End If
  29. Console.ReadLine()
  30. End Sub
  31. End Module

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

  1. Line 1 - a is not equal to b
  2. Line 2 - a is not less than b
  3. Line 3 - a is greater than b
  4. Line 4 - a is either less than or equal to b
  5. 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 运算符 - 它将字符串与模式进行比较。

转载本站内容时,请务必注明来自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号