As the title says I need to know if there is a corresponding syntax as java's ...
in method parameters, like
void printReport(String header, int... numbers) { //numbers represents varargs System.out.println(header); for (int num : numbers) { System.out.println(num); } }
(code courtesy of wikipedia)
In mathematics and in computer programming, a variadic function is a function of indefinite arity, i.e., one which accepts a variable number of arguments.
The special syntax *args in function definitions in python is used to pass a variable number of arguments to a function. It is used to pass a non-key worded, variable-length argument list. The syntax is to use the symbol * to take in a variable number of arguments; by convention, it is often used with the word args.
A variable argument function (variadic function) is a function that can accept an undefined number of arguments. In many programming languages, formatted output functions are defined as variadic functions. In C++, variable argument functions are declared with the ellipsis (...) in the argument list field.
Yes you can write something like this:
void PrintReport(string header, params int[] numbers) { Console.WriteLine(header); foreach (int number in numbers) Console.WriteLine(number); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With