O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 False if expression is one of the value data types (Byte, Short, Integer, Long, Single, Double, Boolean, Date, or Char).

  • IsReference returns True if expression is a reference data type (String or Object), including an object of a specific type, such as a Collection object.

  • IsReference returns True if expression is an array, since an array is a reference type.

  • IsReference returns False if expression 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 True oObj = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required