This code:
public void collide(int x, int y)
{
   int foodthen=0;
   for(int xt=0;xt<150;xt++)
   {
      for(int  yt=0;yt<55;yt++)
      {
~        if(MainClass.tilesSet[yt,xt].food=true)
         {
            foodthen++;
         }
      }
   }
   Debug.WriteLine("Food then: "+foodthen);
   if(this.Equals(MainClass.fridge)||this.Equals(MainClass.tree))
   {
      if(MainClass.tilesSet[y,x].food)
      {
         MainClass.tilesSet[y,x].food=false;
         MainClass.Log("You found some food!");
         MainClass.player.food++;
      }
      else
      {
         MainClass.Log("There is no food... :(");
      }
    }
    MainClass.player.updateFood();
 }
This throws a NullReferenceException at the line marked with a '~'. The same code as in the line marked with a '#' seems to be okay, no exception thrown when I test it without the throwing code. Why does it only happen when in a for loop?
 
     
     
     
    