SyntaxDim result As Boolean = TypeOf varName Is typeName or: Dim result As Boolean = TypeOf varName IsNot typeName
DescriptionThe TypeOf operator indicates whether an instance of data is of a specific type (true) or not (False). It is always used with the Is or IsNot keyword, followed by a valid .NET type. It is most often used with If...Then...Else statements, as in: If (TypeOf someVariable Is Integer) Then ' ----- Integer-specific code here. End If New in 2005. Visual Basic 2005 introduced a new IsNot keyword that negates the Boolean result of the TypeOf operator. If (TypeOf someVariable IsNot Integer) Then ' ----- Non-Integer-specific code here. End If Before 2005, the equivalent of this syntax required the use of the Not operator. If Not (TypeOf someVariable Is Integer) Then ' ----- Non-Integer-specific code here. End If Version DifferencesVisual Basic 2005 includes a new IsNot keyword. It was not available in earlier versions of VB for .NET or in VB 6. See AlsoIs Operator, IsNot Operator |