Name
Is Operator
Syntax
object1Isobject2
-
object1(required; Object or any reference type) -
object2(required; Object or any reference type)
Return Value
Boolean
Description
Compares two object variables or reference variables to determine whether they reference the same object
Rules at a Glance
Both
object1andobject2must be reference-type variables. This includes string variables, object variables, and array variables, for instance.The operation returns a result of
Trueif the references are identical andFalseif they are not.It is also possible to determine whether an object contains a valid reference by replacing
object2with the specialNothingkeyword. For example:If
oDriveIs Nothing Thenreturns
TrueifoDrivedoes not refer to an object andFalseif it does. This is the only method that should be used to test for an uninitialized object reference.
Programming Tips and Gotchas
You can call the IsReference function to ensure that both
object1andobject2are reference types.You may wonder why there is a special
Isoperator for reference types. When you perform a comparison of scalar variables, you want to know if their values are the same. But in the case of objects, you want to know if two references point to a single object. (Since many objects have identical property values, a test for equal values is meaningless.) Hence, theIsoperator is used for this purpose.Typically, the
Isoperator is used in anIf...Then...Elseconstruct to take some action if two reference-type ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access