Partilhar via


Como: Retornar uma matriz de um procedimento ou propriedade (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 Instrução Function (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 Instrução Return (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 Propriedade declaração.

  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
    

Consulte também

Tarefas

Como: Ceder uma matriz a outra matriz (Visual Basic)

Como: Alterar uma matriz para uma matriz diferente (Visual Basic)

Como: Passar uma matriz para um procedimento ou propriedade (Visual Basic)

Solucionando problemas de matrizes (Visual Basic)

Conceitos

Matrizes no Visual Basic