title: Cant access list in other class with for loop
body: <p>I have a real brain teaser right here and I can't figure out what I am doing wrong since the code looks absolutely normal.</p>
  
  <p>Little background information:
  Since I've started working in the XNA/MonoGame environment for about 2 days now I wanted to start off with something easy. I'm currently building an astroid defender like game, and I'm working on a collision check. Before I even got to the collision, I found that I got a rather odd null reference while im using a for loop to loop through all enemies inside a list. The list however is in another class.</p>
  
  <p>Upon startup I initizalize a SpawnManager class that immediately creates 20 enemies when the class has been made like so:</p>
  
  <pre><code>class SpawnManager
  {
      //Draw
      ContentManager myContentManager;
  
      //Enemies
      public List&lt;Enemy&gt; enemy = new List&lt;Enemy&gt;();
  
      public void LoadContent(ContentManager theContentManager)
      {
          myContentManager = theContentManager;
  
          for (int i = 0; i &lt; 20; i++)
          {
              Enemy newEnemy = new Enemy(new Vector2((800 / (20 + 1) * i + 16.5f), 20), 500, 50, 25, 10, 2500, 100, 1, 3, 2, false);
              newEnemy.LoadContent(myContentManager);
              enemy.Add(newEnemy);
          }
      }
  </code></pre>
  
  <p>Then whenever I fire a bullet with my spaceship, it will create a bulletclass like so:</p>
  
  <pre><code>public class Bullet : PlayerScript
  {
      //Enemy enemy;
      SpawnManager spawnManager;
      PlayerScript playerScript;
  
      private Texture2D _bullet;
      private Rectangle _hitBox;
      public float xPos = 0;
      public float yPos = 0;
  
      public bool isActive = false;
  
      public void LoadContent(ContentManager theContentManager)
      {
          _bullet = theContentManager.Load&lt;Texture2D&gt;("Graphics/citem");
          _hitBox = new Rectangle(0, 0, _bullet.Width, _bullet.Height);
      }
  
      public void Update(GameTime gameTime)
      {
          //Movement.
          yPos -= 13.5f;
  
          //Collision.
              for (int i = 0; i &lt; spawnManager.enemy.Count; i++)
              {
                  //Console.WriteLine(spawnManager.enemy.Count);
              }
       }
  </code></pre>
  
  <p>When while im holding space to fire bullets, I immediately get a null reference error, hightlighting the for loop part. I've read some posts on the internet saying that the Enemy List might be null or empty, but even if that is the case, that shouldn't really matter as my code structure goes as follows:</p>
  
  <p>Game1 Initialize -> add SpawnManager -> add Enemies + push them in the Enemy list.</p>
  
  <p>So when the enemies are on the screen, they are basically already added to the Enemy list and the List shouldn't be null or empty. </p>
  
  <p>Also, might there be an easier or more efficient way to check for collision? Because everytime I'm creating a bullet, a bullet.Update script will start looping through all enemies like a madman until it reaches an enemy, checking which enemy it is, applying changes to it and adding itself to a pool. (Ofcourse when its in the pool I wont update the Bullet script). Since this astroid defender is more like a little bullet hell, shooting 100 bullets per few seconds, will cause a lot of looping in total. I just came over to XNA / MonoGame C# after spending 1.5 years in Unity, and in Unity everything seems so simple, OnCollisionEnter ftw! :)</p>
  
  <p>Still, I'm pretty sure its a total ID-10-T error on my side, but I just cant wrap my head around it, any help would be gratefully appreciated :)</p>
  
  <p>P.S: If anything is stated unclear, I'd be glad to edit this question!</p>