Syntax Dim result As Boolean = object1 IsNot { object2 | Nothing }
object1 (required; Object or any reference type) An object or instance for comparison
object2 (required; Object or any reference type) An object or instance for comparison Description New in 2005. The IsNot operator compares two object references and indicates whether they refer to a different underlying instance (true) or the same instance (False). It is most often used with If...Then...Else statements, as in: If (someVariable IsNot someOtherVariable) Then ' ----- Non-equivalent-specific code here. End If Comparing a variable with Nothing tests whether an instance has already been assigned to that variable. If (someVariable IsNot Nothing) Then ' ----- The variable is already defined. End If The IsNot operator is the negation of the Is operator. Before Visual Basic 2005, the functionality of the IsNot operator had to be done with the Not operator. If Not (someVariable Is Nothing) Then ' ----- The variable is already defined. End If Usage at a Glance Both object1 and object2 must be reference-type variables. This includes string variables, object variables, and array variables. You can call the IsReference function to ensure that both object1 and object2 are reference types. The IsNot operator can be used with the TypeOf operator to determine if an object reference is not of a specific type. The IsNot operator reports that uninitialized reference types are equal. For example, the following comparison equates to TRue: Dim emptyForm As Windows.Forms.Form Dim ordinaryString As String If (emptyForm IsNot ordinaryString) Then MsgBox("Different") ' ----- The MsgBox will not appear. Version Differences The IsNot operator is new with Visual Basic 2005. In .NET, strings and arrays are reference types. In VB 6, strings and arrays are not reference types and, therefore, cannot be used with the IsNot operator. See Also Is Operator, TypeOf Operator |