Is 运算符 (Visual Basic)

比较两个对象引用变量。

result = object1 Is object2

部件

  • result
    必选。 任何 Boolean 值。

  • object1
    必选。 任何 Object 名称。

  • object2
    必选。 任何 Object 名称。

备注

Is 运算符确定两个对象引用是否引用同一个对象。 但是,它不执行值比较。 如果 object1 和 object2 引用同一个对象实例,则 result 为 True;如果它们不引用同一个对象,则 result 为 False。

还可以将 Is 与 TypeOf 关键字一起使用,以组成 TypeOf...Is 表达式,此表达式测试对象变量是否与数据类型兼容。

备注

Is 关键字还在 Select...Case 语句 (Visual Basic) 中使用。

示例

下面的示例使用 Is 运算符比较对象引用对。 结果赋值为 Boolean 值,它表示两个对象是否相同。

Dim myObject As New Object
Dim otherObject As New Object
Dim yourObject, thisObject, thatObject As Object
Dim myCheck As Boolean
yourObject = myObject
thisObject = myObject
thatObject = otherObject
' The following statement sets myCheck to True.
myCheck = yourObject Is thisObject
' The following statement sets myCheck to False.
myCheck = thatObject Is thisObject
' The following statement sets myCheck to False.
myCheck = myObject Is thatObject
thatObject = myObject
' The following statement sets myCheck to True.
myCheck = thisObject Is thatObject

如前面的示例所演示的一样,可以使用 Is 运算符测试早期绑定对象和后期绑定对象。

请参见

参考

TypeOf 运算符 (Visual Basic)

IsNot 运算符 (Visual Basic)

Visual Basic 中的运算符优先级

按功能列出的运算符 (Visual Basic)

概念

比较运算符 (Visual Basic)

Visual Basic 中的运算符和表达式