cannot pass array as a function parameter?

  • Thread starter Thread starter Matthew Louden
  • Start date Start date
M

Matthew Louden

public static int[] getFreq(string[] s)
{...
}

int[] res = getFreq({"eee", "ewsww"});

WordFreq.cs(7,23): error CS1525: Invalid expression term '{'
WordFreq.cs(7,24): error CS1026: ) expected
WordFreq.cs(7,29): error CS1002: ; expected
WordFreq.cs(7,29): error CS1525: Invalid expression term ','
WordFreq.cs(7,31): error CS1002: ; expected
WordFreq.cs(7,38): error CS1002: ; expected
WordFreq.cs(7,39): error CS1525: Invalid expression term ')'
 
Matthew Louden said:
public static int[] getFreq(string[] s)
{...
}

int[] res = getFreq({"eee", "ewsww"});

WordFreq.cs(7,23): error CS1525: Invalid expression term '{'
WordFreq.cs(7,24): error CS1026: ) expected
WordFreq.cs(7,29): error CS1002: ; expected
WordFreq.cs(7,29): error CS1525: Invalid expression term ','
WordFreq.cs(7,31): error CS1002: ; expected
WordFreq.cs(7,38): error CS1002: ; expected
WordFreq.cs(7,39): error CS1525: Invalid expression term ')'

You need to tell it that it wants to be a string array:

int[] res = getFreq( new string[] {"eee", "ewsww"} );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top