title: Trying to make a 2D array of lists
body: <p>I'm trying to write a model containing digital organisms. Within the model i'd liek the environment to be a fixed 2-d array, but each cell needs to contain a list of the organisms in it. I tried using a jagged array, but as the number of occupied elements varies quite a bit throughout the programm run, i need to use something more flexible than an array. I've tried making a 2-D array of the type list, but im getting errors with it.</p>
  
  <pre><code>    List&lt;Creature&gt;[,] theWorld;
  
  
      public Environment()
      { 
          List&lt;Creature&gt;[,] theWorld = new List&lt;Creature&gt;[100,100];
      }
  
      public void addCreature(Creature c)
      {
         for (int x = 0; x &lt; 100; x++)
          {
              for (int y = 0; y &lt; 100; y++)
              {
                  theWorld[x, y].Add (c);
  
              } } }
  </code></pre>
  
  <p>this is the segment where i'm trying to declare the array at the beginning, as a type that holds lists (of the organisms), and later i try to add a creature (c) to each of the lists in each element of the array.</p>
  
  <p>when i run it i get the following error message-</p>
  
  <p>"An unhandled exception of type 'System.NullReferenceException' occurred in HGT_sim_2.exe</p>
  
  <p>Additional information: Object reference not set to an instance of an object."</p>
  
  <p>and the line "World[x, y].Add (c);" is highlighted.</p>
  
  <p>If anyone can tell me what i'm doing wrong, and even better, a way around the problem, it'd be amazing.
  thank you ain advance!</p>