title: How to resolve NullReference Exception on String Array Objects?
body: <p>I have a <code>String array</code> object in a class, i.e, <code>String[] particulars</code> which I want to initialize during runtime. The same code segment worked for another class object which was not array though.   Here <code>nd</code> is an object of class.</p>
  
  <p><code>int i=0;
      foreach (DataRow row1 in dt1.Rows)
             {
                  nd.particulars[i] = row1["floor"].ToString();
                  nd.quantity[i] = (double)row1["area"];
                  nd.rate[i] = (double)row1["rate"];
                  nd.amount[i] = (double)row1["amount"];
                  i++;
             }</code></p>
  
  <p>The following code is throwing some <code>NullReferenceException</code>.  The error says:</p>
  
  <p><strong>Object reference not set to an instance of an object.</strong></p>
  
  <p>The class definition is as:</p>
  
  <pre><code>class NoteDetails
   {
      public string[] particulars;
      public double[] quantity;
      public double[] rate;
      public double[] amount;
  
      public string[] mparticulars;
      public double[] mquantity;
      public double[] mrate;
      public double[] mamount;
  
      public NoteDetails()
      {
          particulars = null;
          quantity = null;
          amount = null;
          rate = null;
  
          mparticulars = null;
          mquantity = null;
          mamount = null;
          mrate = null;
      }
   }
  </code></pre>
  
  <p>Please tell me what I'm doing wrong?</p>