簡體   English   中英

我無法將數組作為函數參數傳遞。如何解決?

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

我正在窗口窗體應用程序上工作,並使函數將數組作為函數參數傳遞,如下所示:

void foobar(int[] foo, string[] bar)
{ 

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

當我調用該函數時,它顯示錯誤:

"Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access."

我該如何解決?

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

new {1, 2,3}new {"a", "b", "c"}在C#中無效(不是正確的聲明數組的方式)。 因此,要傳遞數組,您必須使用正確的語法,即new int[] {1, 2,3}, new string[] {"a", "b", "c"}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM