Is Operator (Visual Basic)
Updated: July 20, 2015
For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.
Compares two object reference variables.
result = object1 Is object2
Is operator determines if two object references refer to the same object. However, it does not perform value comparisons. If
object2 both refer to the exact same object instance,
True; if they do not,
Is can also be used with the
TypeOf keyword to make a
Is expression, which tests whether an object variable is compatible with a data type.
The following example uses the
Is operator to compare pairs of object references. The results are assigned to a
Boolean value representing whether the two objects are identical.
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
As the preceding example demonstrates, you can use the
Is operator to test both early bound and late bound objects.