Does C# support a variable number of arguments, and how?

前端 未结 4 942
自闭症患者
自闭症患者 2020-11-27 19:17

Does C# support a variable number of arguments?

If yes, How does C# support variable no of arguments?

What are the examples?

How are variable argum

4条回答
  •  孤街浪徒
    2020-11-27 20:05

    I assume you mean a variable number of method parameters. If so:

    void DoSomething(params double[] parms)
    

    (Or mixed with fixed parameters)

    void DoSomething(string param1, int param2, params double[] otherParams)
    

    Restrictions:

    • They must all be the same type (or of a child type) as is true for arrays as well
    • There can only be one for each method
    • They must come last in the parameter list

    That's all I can think of at the moment though there could be others. Check the documentation for more information.

提交回复
热议问题