title: How do I create a multidimensional array of objects in c#
body: <p>I am trying to make a script that dynamically generates world chunks by making a height map then filling out the terrain blocks from there. My problem is creating a 2 dimensional array of objects.</p>
  
  <pre><code>public class Chunk
  {
      public Block[,] blocks;
  
      Generate(){
          //code that makes a height map as a 2 dimensional array as hightmap[x,y]=z
          //convert heightmap to blocks
          for (int hmX = 0; hmX &lt; size; hmX++)
          {
              for (int hmY = 0; hmY &lt; size; hmY++)
              {
                  blocks[hmX, hmY] = new Block(hmX, hmY, heightmap.Heights[hmX, hmY], 1);
              }
          }
      }
  }
  </code></pre>
  
  <p>this is giving me the error: </p>
  
  <blockquote>
    <p>NullReferenceException was unhandled, Object reference not set to an
    instance of an object.</p>
  </blockquote>