
480
|
Chapter 12: The Language Reference
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
TypeOf Operator
Syntax
Dim result As Boolean = TypeOf varName Is typeName
or:
Dim result As Boolean = TypeOf varName IsNot typeName
varName (required; any)
The variable, instance, or expression to compare with a data type
typeName (required)
The class, interface, structure, or other type name against which to compare
varName
Description
The 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 Differences
Visual Basic 2005 includes a new IsNot keyword. It was not available in earlier
versions of VB for .NET or in VB 6.
See Also
Is Operator, IsNot Operator
UBound Function
Class
VisualBasic.Information
Syntax
Dim result ...