一个类型,但像变量一样使用?

时间:2013-12-01 22:57:50

标签: c# variables types

    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

        }

有人可以帮我解决这个问题吗,因为我无法看清楚哪里出错......

1 个答案:

答案 0 :(得分:7)

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

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