Name
IsReference Function
Class
Microsoft.VisualBasic.Information
Syntax
IsReference(expression)-
expression(required; any)
Return Value
Boolean
Description
Returns True if
expression contains reference type data,
as opposed to value type data
Rules at a Glance
IsReference returns
Falseifexpressionis one of the value data types (Byte, Short, Integer, Long, Single, Double, Boolean, Date, or Char).IsReference returns
Trueifexpressionis a reference data type (String or Object), including an object of a specific type, such as aCollectionobject.IsReference returns
Trueifexpressionis an array, since an array is a reference type.IsReference returns
Falseifexpressionis a structure, since a structure is a value type.
Example
Private Class CEmployee
...
End Class
' The following message will display
Dim obj As Object
If IsReference(obj) Then
MsgBox("obj is reference type, but is Nothing")
End If
' The following message will display
' (CEmployee is a class module)
Dim c As New CEmployee( )
If IsReference(c) Then
MsgBox("c is reference type")
End If
' The following message does NOT display
Dim i As Integer = 4
If IsReference(i) Then
MsgBox("Integer is reference type")
End IfProgramming Tips and Gotchas
Just because a variable has been declared to be of type Object does
not mean that the IsReference function will
return True when that variable is passed to it as
an argument. Consider the following code:
Dim oObj As Object Console.WriteLine(IsReference(oObj)) 'Returns True oObj = ...