struct Player
{
public string Name;
public int X;
public int Y;
}
static Player[] players = new Player[amountofPlayers];
for (int i = 1; i < amountofPlayers; i = i + 1)
{
int displayNumber = i + 1;
Console.Write("Please enter the name of player " + displayNumber + ": ");
Player[i].Name = Console.ReadLine(); // The error is here
}
有人可以帮我解决这个问题吗,因为我无法看清楚哪里出错......
答案 0 :(得分:7)
Player
是类型/结构,players
是Player[]
,所以请使用:
players[i].Name = Console.ReadLine(); // instead of Player[i]