IsReference Function |
Microsoft.VisualBasic.Information
IsReference( expression )
Boolean
Returns True if expression contains reference type data, as opposed to value type data
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.
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
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 = New CEmployee Console.WriteLine(IsReference(oObj)) 'Returns True oObj = 3 Console.WriteLine(IsReference(oObj)) 'Returns False oObj = "This is a string" Console.WriteLine(IsReference(oObj)) 'Returns True
In other words, the IsReference function returns True only if a variable of type Object is Nothing or if its data subtype is one of the reference types (that is, an instance of a class or a string). If its data subtype is a value type, the function returns False .
The IsReference function is new to VB.NET.