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
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个问题吗,因为我看不出我哪里错了...
任何人都可以帮我解决问题吗?
struct Player
{
public string Name;
public int X;
public int Y;
}
static Player[] players = new Player[amountofPlayers];
static void ResetGame() {
Console.WriteLine("Welcome to the game!");
Console.Write("How many player will be taking part today: ");
string playerNo = Console.ReadLine();
amountofPlayers = int.Parse(playerNo);
if (amountofPlayers <= 4)
{
for (int i = 0; i < amountofPlayers; i = i + 1)
{
int displayNumber = i + 1;
Console.Write("Please enter the name of player " + displayNumber + ": …Run Code Online (Sandbox Code Playgroud) if (testModetrue)
{
try
{
Console.Write("What number do you want the roll to be set to? (1-6)");
string diceString = Console.ReadLine();
int diceCheck = int.Parse(diceString);
if ((diceCheck >= minDiceValue) || (diceCheck <= maxDiceValue))
{
diceNo = int.Parse(diceString);
}
else if ((diceCheck <= minDiceValue) || (diceCheck >= maxDiceValue))
{
Console.WriteLine("Please enter a number between 1-6.");
break;
}
}
catch (Exception)
{
Console.WriteLine("An error has occured.");
return;
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码检查给出的答案是否超过6或低于1,但无论何时我运行它,无论如何它会抛出数组错误,有人帮忙吗?