Is 运算符 (Visual Basic)
更新:2007 年 11 月
比较两个对象引用变量。
result = object1 Is object2
各部分说明
result
必选。任何 Boolean 值。object1
必选。任何 Object 名称。object2
必选。任何 Object 名称。
备注
Is 运算符确定两个对象引用是否引用同一个对象。但是,它不执行值比较。如果 object1 和 object2 引用同一个对象实例,则 result 为 True;如果它们不引用同一个对象,则 result 为 False。
还可以将 Is 与 TypeOf 关键字一起使用,以组成 TypeOf...Is 表达式,此表达式测试对象变量是否与数据类型兼容。
示例
下面的示例使用 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 运算符测试早期绑定对象和后期绑定对象。