Creating methods with infinite parameters?

后端 未结 8 1624
再見小時候
再見小時候 2021-01-31 13:44

In C# you can do this:

foo = string.Format(\"{0} {1} {2} {3} ...\", \"aa\", \"bb\", \"cc\" ...);

This method Format() accepts in

8条回答
  •  粉色の甜心
    2021-01-31 14:42

    Use the params keyword. Usage:

    public void DoSomething(int someValue, params string[] values)
    {
        foreach (string value in values)
            Console.WriteLine(value);
    }
    

    The parameter that uses the params keyword always comes at the end.

提交回复
热议问题