user3055553
user3055553

Reputation: 55

A type but is used like a variable?

    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

        }

Can someone help me to fix this, as I cannot see what where I am going wrong...

Upvotes: 3

Views: 809

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460058

Player is the type/struct, players the Player[], so use this:

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

Upvotes: 8

Related Questions