I have a method which takes params object[] such as:
void Foo(params object[] items)
{
Console.WriteLine(items[0]);
}
When I pass two object arrays to this method, it works fine:
Foo(new object[]{ (object)"1", (object)"2" }, new object[]{ (object)"3", (object)"4" } );
// Output: System.Object[]
But when I pass a single object[], it does not take my object[] as the first param, instead it takes its all elements like I wanted to pass them one by one:
Foo(new object[]{ (object)"1", (object)"2" });
// Output: 1, expected: System.Object[]
How do I pass a single object[] as a first argument to a params array?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…