C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Here: PrintValues receives a ParamArray. We can call it with zero, one or many arguments.
Warning: For performance, avoiding ParamArray is often a better solution. An array is created for each call to a ParamArray method.
VB.NET program that uses ParamArray argument
Module Module1
Sub PrintValues(ParamArray values() As Integer)
' Display Length of array.
Console.WriteLine("Count: " + values.Length.ToString())
' Loop over ParamArray values.
For Each value As Integer In values
Console.WriteLine(value)
Next
End Sub
Sub Main()
' Use ParamArray method.
PrintValues()
PrintValues(1)
PrintValues(10, 20, 30)
End Sub
End Module
Output
Count: 0
Count: 1
1
Count: 3
10
20
30