int PlayerAmount = 10;
int CurrentPlayer = 0;
Player[] player = new Player[PlayerAmount];
while (true)
{
string Input;
Console.WriteLine("What would you like to do?");
Console.WriteLine("1. Create new player and score.");
Console.WriteLine("2. Display Highscores.");
Console.WriteLine("3. Write out to XML file.");
Console.Write("Input Number: ");
Input = Console.ReadLine();
if (Input == "1")
{
if (CurrentPlayer >= PlayerAmount)
{
Console.WriteLine();
Console.WriteLine("MAX AMOUNT OF PLAYERS HAS BEEN REACHED!");
Console.WriteLine();
}
else
{
string PlayerName;
string Score;
Console.WriteLine();
Console.WriteLine("-=CREATE NEW PLAYER=-");
Console.Write("Player name: ");
PlayerName = Console.ReadLine();
Console.Write("Player score: ");
Score = Console.ReadLine();
//=========================================
//THIS IS WHERE THE ERROR OCCURS===========
//=========================================
player[CurrentPlayer].Name = PlayerName;
Console.WriteLine("Player \"" + player[CurrentPlayer].Name + "\" with the score of \"" + player[CurrentPlayer].Score + "\" has been created successfully!" );
Console.WriteLine();
}
}
else if (Input == "2")
{
Console.WriteLine("Displaying the highscores");
}
else if (Input == "3")
{
Console.WriteLine("Writing to XML file");
}
else
{
Console.WriteLine("INVALID INPUT");
}
}
我已经尝试使用字符串复制,但这只是给了我同样的错误,我已经在代码中指出了问题,但是如果你看不到它是复制玩家名称的位置:“玩家 [ CurrentPlayer].Name = PlayerName;"
提前致谢