Reputation: 97
I am working on a window form application and making a function pass an array as function parameter as shown below:
void foobar(int[] foo, string[] bar)
{
}
//calling
foobar(new {1, 2,3}, new {"a", "b", "c"});
when I call the function, it displays the error:
"Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access."
how can I solve it?
Upvotes: 0
Views: 217
Reputation: 1
new {1, 2,3}
and new {"a", "b", "c"}
are not valid (not the correct way to declare the array) in C#. So to pass an array you have to use proper syntax i.e. new int[] {1, 2,3}, new string[] {"a", "b", "c"}
.
Upvotes: 0
Reputation: 7204
//calling
foobar(new int[] {1, 2,3}, new string[] {"a", "b", "c"});
Upvotes: 5