Name
IsArray Function
Class
Microsoft.VisualBasic.Information
Syntax
IsArray(varname
)
-
varname
(required; any variable) A variable that may be an array
Return Value
Boolean (True
or False
)
Description
Tests whether an object variable points to an array
Rules at a Glance
If the variable passed to IsArray is an array or
contains an array, True
is returned; otherwise,
IsArray returns False
.
Example
The following code displays True
:
Dim s( ) As Integer = {1, 2} Dim t As Object t = s MsgBox(IsArray(t))
Programming Tips and Gotchas
Due to the nature of Objects, it is not always obvious if an Object variable contains an array, especially if you have passed the variable to a function and the function may or may not have attached an array to the variable. Calling the array function UBound or trying to access an element in an array that does not exist will generate an error. In these situations, you should first use the IsArray function to determine if you can safely process the array.
An uninitialized array returns
False
. For example:Dim strArr( ) As String Console.WriteLine(IsArray(strArr)) ' Returns False
Array-like data structures, such as the
Collection
object, returnFalse
when passed to the IsArray function.
VB.NET/VB 6 Differences
In VB 6, the IsArray function returns
True
when passed an uninitialized array. In
VB.NET, it returns False
.
Get VB.NET Language in a Nutshell, Second Edition 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.