gpt4 book ai didi

c# - 一种类型但像变量一样使用?

转载 作者:行者123 更新时间:2023-11-30 13:57:38 24 4
gpt4 key购买 nike

    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

}

谁能帮我解决这个问题,因为我看不出哪里出了问题...

最佳答案

Player 是类型/结构,playersPlayer[],所以使用这个:

players[i].Name = Console.ReadLine(); // instead of Player[i]

关于c# - 一种类型但像变量一样使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20318333/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com