Using ParamArray to create variable-length parameter lists. : Varied length method parameter « Class Module « VB.Net Tutorial






Module Tester

   Sub Main()
      AnyNumberArguments()
      AnyNumberArguments(2, 3)
      AnyNumberArguments(7, 8, 9, 10)

   End Sub ' Main

   Sub AnyNumberArguments(ByVal ParamArray array1 _
      As Integer())

      Dim i, total As Integer
      total = 0

      If array1.Length = 0 Then
         Console.WriteLine(" received 0 arguments.")
      Else
         Console.Write("The total of ")

         For i = 0 To array1.GetUpperBound(0)
            Console.Write(array1(i) & " ")
            total += array1(i)
         Next

         Console.WriteLine("is {0}.", total)
      End If

   End Sub

End Module
received 0 arguments.
The total of 2 3 is 5.
The total of 7 8 9 10 is 34.








6.7.Varied length method parameter
6.7.1.Using ParamArray to create variable-length parameter lists.
6.7.2.Varied length Method parameter
6.7.3.ParamArray Parameter (Variable Args)