How to pass a single object[] to a params object[]

前端 未结 7 1477
有刺的猬
有刺的猬 2020-11-27 15:43

I have a method which takes params object[] such as:

void Foo(params object[] items)
{
    Console.WriteLine(items[0]);
}

When I pass two o

7条回答
  •  [愿得一人]
    2020-11-27 15:55

    You need to encapsulate it into another object[] array, like this:

    Foo(new Object[] { new object[]{ (object)"1", (object)"2" }});
    

提交回复
热议问题