Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9045347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:16:44+00:00 2026-06-16T11:16:44+00:00

int PlayerAmount = 10; int CurrentPlayer = 0; Player[] player = new Player[PlayerAmount]; while

  • 0
int PlayerAmount = 10;
int CurrentPlayer = 0;
Player[] player = new Player[PlayerAmount];

while (true)
{
    string Input;
    Console.WriteLine("What would you like to do?");
    Console.WriteLine("1. Create new player and score.");
    Console.WriteLine("2. Display Highscores.");
    Console.WriteLine("3. Write out to XML file.");
    Console.Write("Input Number: ");
    Input = Console.ReadLine();
    if (Input == "1")
    {
        if (CurrentPlayer >= PlayerAmount)
        {
            Console.WriteLine();
            Console.WriteLine("MAX AMOUNT OF PLAYERS HAS BEEN REACHED!");
            Console.WriteLine();
        }
        else
        {
            string PlayerName;
            string Score;

            Console.WriteLine();
            Console.WriteLine("-=CREATE NEW PLAYER=-");
            Console.Write("Player name: ");
            PlayerName = Console.ReadLine();
            Console.Write("Player score: ");
            Score = Console.ReadLine();

            //=========================================
            //THIS IS WHERE THE ERROR OCCURS===========
            //=========================================
            player[CurrentPlayer].Name = PlayerName;


            Console.WriteLine("Player \"" + player[CurrentPlayer].Name + "\" with the score of \"" + player[CurrentPlayer].Score + "\" has been created successfully!" );
            Console.WriteLine();
        }
    }
    else if (Input == "2")
    {
        Console.WriteLine("Displaying the highscores");
    }
    else if (Input == "3")
    {
        Console.WriteLine("Writing to XML file");
    }
    else
    {
        Console.WriteLine("INVALID INPUT");
    }
}

I’ve already tried to use string copy but that just gives me the same error, i’ve already pointed the problem out in the code, but if you can’t see it its where the player name is being copied: “player[CurrentPlayer].Name = PlayerName;”

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T11:16:51+00:00Added an answer on June 16, 2026 at 11:16 am

    You don’t initialize each member of the Player array. After doing:

    Player[] player = new Player[PlayerAmount];
    

    you may want to do this as well:

    for (int i = 0; i < PlayerAmount; i++)
    {
        Player[i] = new Player();
    }
    

    Because beforehand, the array contains a bunch of null references only.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

int[] arr = new int[5]; Console.WriteLine(arr.Count.ToString());//Compiler Error Console.WriteLine(((ICollection)arr).Count.ToString());//works print 5 Console.WriteLine(arr.Length.ToString());//print 5 Do you
int x; if (Q()) x = 123; if (R()) Console.WriteLine(x); // illegal int x;
int queryVector = 1; double similarity = 0.0; int wordPower; String[][] arrays = new
int* p_bob = new int; *p_bob = 78; The above code makes sense to
int a[2]; This in memory actually looks like: //Assuming int is 2 bytes add=2000,
int hash (const string &key, int tableSize) { int hashVal = 0; for (int
int port = 18000; DatagramSocket serverSocket = new DatagramSocket(port); byte[] receiveData = new byte[8];
int locctr = 0,toknum = 0; String temp; String d; String [] tok =
int n; std::cin >> n; std::string s = ; std::getline(cin, s); I noticed that
int LinkedList::DoStuff() { Node *Current = next_; while ( Current != NULL ) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.