Is there a way in c# to declare a function that can take a dynamic number of same type arguments without overloading the function like:
in foo(...)
foo(1) foo(1, 2) foo(1, 2, 3...)
Is there a way in c# to declare a function that can take a dynamic number of same type arguments without overloading the function like:
in foo(...)
foo(1) foo(1, 2) foo(1, 2, 3...)
Use params keyword:
int foo(params int[] arguments)
{
....
}
Using the ParamArrayAttribute you can get the desired effect.
Public void Foo(params int[] list){}
Examples of calling the method:
Foo(1);
Foo(1,2);
Foo(1,2,3);
Please see here for more info on Msdn multiple parameters