In C#, I'm creating an array of "Player" objects. Each player has two attributes, and name and a score, which are left blank when the player is created to be set later. The code compiles, but when it tries to set the name or score of a player in the array I get a null reference exception. The code looks something like this, substituting the variables I'm using with constants for the sake of simplification:
Player[] playerArray = new Player[5];
playerArray[0].Name = "hello";
I tried creating a Player object that wasn't in an array and it worked fine, but for some reason it won't work in the array. Am I just missing a step or something? I feel like it should be an easy fix and that I'm just missing something obvious.
Never mind, I figured it out. I tried deleting the thread, but it won't let me.