How to: Return an Array from a Procedure or Property (Visual Basic)
You return an array the same way you return any other data type. You supply the array type as the return type of the procedure or property.
To return an array from a Function procedure
Specify the array type (rank and element data type) as the return type in the Function Statement (Visual Basic).
Within the procedure, declare a local array variable with the same rank and element data type.
Include this local array variable in the Return Statement (Visual Basic). Do not follow the array name with parentheses.
Public Function splitNumber(ByVal number As Double) As Char() Dim characters() As Char ' Insert code to split number into characters. Return characters End Function Dim piCharacters() As Char = splitNumber(3.14159265)
To return an array from a property
Specify the array type (rank and element data type) as the property type in the Property Statement.
Within the property's Get procedure, or in a place available to the Get procedure, declare a local array variable with the same rank and element data type.
Include this local array variable in the Return statement. Do not follow the array name with parentheses.
Private nameList() As String Public Property stationNames As String() Get Return nameList End Get Set(ByVal Value As String()) ' Insert code to store nameList values. End Set End Property Dim listOfNames() As String = stationNames
See Also
Tasks
How to: Assign One Array to Another Array (Visual Basic)
How to: Change an Array to a Different Array (Visual Basic)
How to: Pass an Array to a Procedure or Property (Visual Basic)
Troubleshooting Arrays (Visual Basic)