If I have a method declared like this:
private void someFunction(object[] param1)
When I call this function do I have to declare the object array as a variable, or is there a quicker / shortcut way to just pass it inline to the function call.
I'm doing it like this:
Object[] myParam1 = new Object[2]
myParam1[0] = "blah";
myParam1[1] = "blah blah";
someFunction(myParam1);
In my real code, not this example, I'm calling COM from Marshal, and the code is getting messy each time I have to declare the arguments.
someFunction(new [] { "blah", "blah blah", "more", "etc" });
Well you could use array initializers that were introduced in C# 3.0:
someFunction(new object[] { "blah", "blah blah" });
and if you have your method declared like this:
private void someFunction(params object[] param1)
you could even write:
someFunction("blah", "blah blah");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With