How to: Pass an Array to a Procedure or Property 

You pass an array the same way you pass any other variable. You supply the array variable name in the appropriate argument when you call the procedure or access the property.

To pass an array to a procedure

  1. Ensure that one of the procedure parameters specifies an array with the same rank (number of dimensions) and element data type.

  2. Supply the array variable at the corresponding place in the argument list. Do not follow the array name with parentheses.

    Public Function findLargest(ByVal numbers() As Double) As Double
        ' Insert code to calculate and return largest number.
    End Function
    Dim testNumbers() As Double = New Double() {5.0, 3.7, 1.2, 7.6}
    Dim largestNumber As Double = findLargest(testNumbers)
    

To pass an array to a property

  1. Ensure that one of the property parameters specifies an array with the same rank (number of dimensions) and element data type.

  2. Supply the array variable at the corresponding place in the argument list. Do not follow the array name with parentheses.

    Public Property bestMatch(ByVal formattedStrings() As String) As Double
        ' Insert Get and Set procedures for number best matching strings.
    End Property
    Dim testStrings() As String = New String() {}
    Dim formattedNumber As Double = bestMatch(testStrings)
    

See Also

Tasks

How to: Declare an Array Variable
How to: Create an Array
How to: Initialize an Array Variable
How to: Assign One Array to Another Array
How to: Change an Array to a Different Array
How to: Return an Array from a Procedure or Property
Troubleshooting Arrays

Other Resources

Arrays in Visual Basic