Ubaid
Ubaid

Reputation: 97

i am unable to pass array as function parameter.how i can solve?

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

Answers (2)

Vivek Nuna
Vivek Nuna

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

Antoine V
Antoine V

Reputation: 7204

//calling
foobar(new int[] {1, 2,3}, new string[] {"a", "b", "c"});

Upvotes: 5

Related Questions