How to pass an array and a single element to a multiple argument method?

后端 未结 4 1452
你的背包
你的背包 2021-01-18 08:59

Example:

public void foo(params string[] s) { ... }

We can call this method with:

a) foo(\"test\", \"test2\", \"test3\") //         


        
4条回答
  •  渐次进展
    2021-01-18 09:11

    Only the last parameter of a method can be a parameter array (params) so you can't pass more than one variable into a method whose signature only takes in params.

    Therefore what you're trying to do in C isn't possible and you have to add that string into an array, or create an overload that also takes a string parameter first.

    public void foo(string firstString, params string[] s)
    {
    } 
    

提交回复
热议问题