Search code examples
c#.netmethodsparameters

Why C# allows that only the last parameter in a method is of "variable length"


From what I know, C# allows that only the last parameter of a method is of "variable length", for example:

T f(A a, params B[] b) allows that if you have A r; .... B x, y, z; .... you can call f like f (r, x, y, z). Why C# doesn't also define something like:

T f(params A[] a, params B[] b)

Solution

  • Because how would the compiler know when the variable arguments for the first parameter stop?

    Pleas tell me what argOne and argTwo should contain inside of the method body:

    void Foo( params object[] argOne, params object[] argTwo )
    {
        // whatever
    } 
    
    Foo( 1, false, "Hello", new object(), 2.3 );