Name
IsReference Function
Class
Microsoft.VisualBasic.Information
Syntax
IsReference(expression
)
-
expression
Use: Required
Data Type: Any
Return Value
Boolean
Description
Returns True
if
expression
contains reference type data,
as opposed to value type data.
Rules at a Glance
IsReference
returnsFalse
ifexpression
is one of the value data types (Byte, Short, Integer, Long, Single, Double, Boolean, Date, or Char).IsReference
returnsTrue
ifexpression
is a reference data type (String or Object), including an object of a specific type, such as aCollection
object.IsReference
returnsTrue
ifexpression
is an array, since an array is a reference type.IsReference
returnsFalse
ifexpression
is 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 If
Programming 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 ...
Get VB .NET Language in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.