Use Array as Function Parameter : Function Parameter « Language Basics « VB.Net






Use Array as Function Parameter

Use Array as Function Parameter
Imports System

Public Class MainClass

    Shared Sub Main(ByVal args As String())
         Dim a As Integer = 5
         Dim b As Integer = 6
         Dim c As Integer = 7
         Console.WriteLine("Calling with three Integers")
         DisplayVals(a, b, c)

         Console.WriteLine("Calling with four Integers")
         DisplayVals(5, 6, 7, 8)

         Console.WriteLine("calling with an array of four Integers")
         Dim explicitArray( ) As Integer = {5, 6, 7, 8}
         DisplayVals(explicitArray)
    End Sub

    Shared Public Sub DisplayVals(ByVal ParamArray intVals( ) As Integer)
        Dim i As Integer
        For Each i In intVals
           Console.WriteLine("DisplayVals {0}", i)
        Next i
    End Sub 'DisplayVals

End Class

           
       








Related examples in the same category

1.Calculates the power of a value, defaults to squareCalculates the power of a value, defaults to square
2.Pass Array as ParametersPass Array as Parameters
3.Two Dimension Array: Pass into a FunctionTwo Dimension Array: Pass into a Function