2015-05-06 52 views
3

所以我有一個類有一個字符串數組的參數。我想要做的是將多個字符串存儲到此類的數組中,這是此類的一部分。代碼看起來像這樣:使用字符串數組作爲對象參數

//Class part of it. Class is called "Event" 
public class Event 
{ 
    public string[] seats = new string [75]; 

    public Event(string[] seats) 
    { 
     this.seats = seats; 
    } 
} 

// the main code that uses "Event" Class 

string[] seatnumber = new string[75]; 
Event show = new Event (seatnumber[]); //And that is where the error comes in. 

任何幫助將不勝感激!

+3

將它放在Event構造函數中時,從seatnumber中刪除括號。 –

+0

括號是類型聲明,構造和元素檢索的一部分。您需要傳遞由'seatnumber'命名的引用變量 –

回答

3

將它放在Event構造函數中時,從seatnumber中刪除括號。

For reference.

3

當你調用一個數組,變量名不需要括號[]

Event show = new Event(seatnumber); 

它像之前在你的代碼稱爲相同:

this.seats = seats; 

seats也是一個數組,雖然你還沒有加入[]當你把它叫做 - 所以沒有錯誤。

相關問題