locked
Using Objects as Arrays? RRS feed

  • Question

  • hey everyone. I need to make 'player' objects, 10 of them so i can call them like player[1].changename("mark");
    Stuff like that. Any tips for me? Heres my code so far

    class Program 
        { 
            static void Main(string[] args) 
            { 
                player[] player = new player[11]; 
                for (int i = 1; i <= 10; i++) { 
                    Console.Write("Enter Player " + i + "'s name: "); 
                    string name = Console.ReadLine(); 
                    player.changename(name);// NOT WORKING 
                } 
                menu.main(); 
            } 
        } 
       class player 
        { 
            string name; 
            string playername() 
            { 
                return name; 
            } 
            void changename(string value) 
            { 
                name = value; 
            } 
     
        } 

    Monday, February 23, 2009 11:48 PM

Answers

  • snowman441555 said:

    hey everyone. I need to make 'player' objects, 10 of them so i can call them like player[1].changename("mark");
    Stuff like that. Any tips for me? Heres my code so far

    class Program 
        { 
            static void Main(string[] args) 
            { 
                player[] player = new player[11]; 
                for (int i = 1; i <= 10; i++) { 
                    Console.Write("Enter Player " + i + "'s name: "); 
                    string name = Console.ReadLine(); 
                    player.changename(name);// NOT WORKING 
                } 
                menu.main(); 
            } 
        } 
       class player 
        { 
            string name; 
            string playername() 
            { 
                return name; 
            } 
            void changename(string value) 
            { 
                name = value; 
            } 
     
        } 



    A "player" is a very different concept, and object, from  a list of "players".
    Mark the best replies as answers. "Fooling computers since 1971."
    Tuesday, February 24, 2009 12:43 AM
    Moderator
  • snowman441555 said:

    hey everyone. I need to make 'player' objects, 10 of them so i can call them like player[1].changename("mark");
    Stuff like that. Any tips for me? Heres my code so far

    class Program 
        { 
            static void Main(string[] args) 
            { 
                player[] player = new player[11]; 
                for (int i = 1; i <= 10; i++) { 
                    Console.Write("Enter Player " + i + "'s name: "); 
                    string name = Console.ReadLine(); 
                    player.changename(name);// NOT WORKING 
                } 
                menu.main(); 
            } 
        } 
       class player 
        { 
            string name; 
            string playername() 
            { 
                return name; 
            } 
            void changename(string value) 
            { 
                name = value; 
            } 
     
        } 



    i think your names are terribly confusing.

    player[i].changename(name);//  MIGHT WORK 

    Mark the best replies as answers. "Fooling computers since 1971."
    Tuesday, February 24, 2009 12:45 AM
    Moderator

All replies

  • snowman441555 said:

    hey everyone. I need to make 'player' objects, 10 of them so i can call them like player[1].changename("mark");
    Stuff like that. Any tips for me? Heres my code so far

    class Program 
        { 
            static void Main(string[] args) 
            { 
                player[] player = new player[11]; 
                for (int i = 1; i <= 10; i++) { 
                    Console.Write("Enter Player " + i + "'s name: "); 
                    string name = Console.ReadLine(); 
                    player.changename(name);// NOT WORKING 
                } 
                menu.main(); 
            } 
        } 
       class player 
        { 
            string name; 
            string playername() 
            { 
                return name; 
            } 
            void changename(string value) 
            { 
                name = value; 
            } 
     
        } 



    A "player" is a very different concept, and object, from  a list of "players".
    Mark the best replies as answers. "Fooling computers since 1971."
    Tuesday, February 24, 2009 12:43 AM
    Moderator
  • snowman441555 said:

    hey everyone. I need to make 'player' objects, 10 of them so i can call them like player[1].changename("mark");
    Stuff like that. Any tips for me? Heres my code so far

    class Program 
        { 
            static void Main(string[] args) 
            { 
                player[] player = new player[11]; 
                for (int i = 1; i <= 10; i++) { 
                    Console.Write("Enter Player " + i + "'s name: "); 
                    string name = Console.ReadLine(); 
                    player.changename(name);// NOT WORKING 
                } 
                menu.main(); 
            } 
        } 
       class player 
        { 
            string name; 
            string playername() 
            { 
                return name; 
            } 
            void changename(string value) 
            { 
                name = value; 
            } 
     
        } 



    i think your names are terribly confusing.

    player[i].changename(name);//  MIGHT WORK 

    Mark the best replies as answers. "Fooling computers since 1971."
    Tuesday, February 24, 2009 12:45 AM
    Moderator