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

  1. Specify the array type (rank and element data type) as the return type in the Function Statement (Visual Basic).

  2. Within the procedure, declare a local array variable with the same rank and element data type.

  3. 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

  1. Specify the array type (rank and element data type) as the property type in the Property Statement.

  2. 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.

  3. 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
    

Community Additions

ADD
Show: