How to pass a single object[] to a params object[]
arrays, c#
Solution
A simple typecast will ensure the compiler knows what you mean in this case.
Foo((object)new object[]{ (object)"1", (object)"2" }));
As an array is a subtype of object, this all works out. Bit of an odd solution though, I'll agree.
Problem
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?