title: C# Nested typed lists
body: <p>I've created a class witch contains a typed list and derives to another class that I created. This looks as follows:</p>
  
  <pre><code>namespace MyIntegretyCheck.Common
  {
      /// &lt;summary&gt;
      /// Description of PolicyErrors.
      /// &lt;/summary&gt;
      public partial class PolicyErrorEndingDates
      {
          public int ID_P {get;set;}
          public DateTime DT_S_E {get;set;}
          public DateTime DT_SC_E {get;set;}
  
          public List&lt;PolicyErrorDescr&gt; Errors {get;set;}
      }
  
      public partial class PolicyErrorDescr
      {
          public string Field1{get;set;}
          public string Field2 {get;set;}
          public string F1IsThanF2 {get;set;}
          public string Message {get;set;}
          public int ErrorLevel {get;set;} //0= Info | 1= Warning | 2= Error
  
      }
  }
  </code></pre>
  
  <p>Now I created a typed list of <code>PolicyErrorEndingDates</code>, added an entry and tried then to add entries of his nested list Errors as follows:</p>
  
  <pre><code>public List&lt;PolicyErrorEndingDates&gt; MyPolicyEndingDates()
  {
  
      DAL.PolicyEndingDates ped = new DAL.PolicyEndingDates();
      List&lt;PolicyErrorEndingDates&gt; MyErrors = new List&lt;PolicyErrorEndingDates&gt;();
  
      foreach(var m in ped.CheckTables())
      {
          bool HasError = false;
          PolicyErrorEndingDates p = new PolicyErrorEndingDates();
          p.ID_P = m.ID_P;
  
          if(m.DT_S_E != m.DT_SC_E)
          {
              PolicyErrorDescr e = new PolicyErrorDescr();
              HasError = true;
              e.Field1 = "DT_S_E";
              e.Field2 = "DT_SC_E";
              e.Message = "blablabla...";
              e.ErrorLevel = 3;
              p.Errors.Add(e);
          }
  
          if(HasError)
              MyErrors.Add(p);
      }
  }
  </code></pre>
  
  <p>The Debugger crashed with the message <code>Object reference not set to an instance of an object</code>, at the line <code>p.Errors.Add(e);</code> inside my <code>if</code>. What did I do wrong? How can I create an instance of the nested list?</p>