Variadic Functions in Visual Basic .NET
Variadic functions can be called with any number of trailing arguments. For example, Console.WriteLine
is a common variadic function.
Here’s a function that will take an arbitrary number of int
s as arguments.
Within the function, nums
is equivalent to an array of Integer
. We can call nums.Length
, iterate over it with For Each
, etc.
Variadic functions can be called in the usual way with individual arguments.
If you already have multiple arguments in an array, apply them to a variadic function using ParamArray
like this:
To run the program, compile the code and execute it.
Another key aspect of functions in Visual Basic .NET is their ability to work with arrays and lists, which we’ll look at next.
Next example: Closures.