所以我有一个具有字符串数组参数的类。我想要做的是将多个字符串存储到此类的数组中。代码看起来像这样:
//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.
非常感谢任何帮助!
答案 0 :(得分:3)
在将其放入Event构造函数时,从seatnumber中删除括号。
答案 1 :(得分:3)
调用数组时,变量名称不需要括号[]
。
Event show = new Event(seatnumber);
它与您之前在代码中调用的相同:
this.seats = seats;
seats
也是一个数组,虽然您在调用它时没有添加[]
,所以没有错误。