title: Recursion in Constructor
body: <p>Please look at the following code snippet. I'm getting a nullreferenceexception at "this.directories.Add(new directory(s));". The recursion seems to be working until it "unwinds", at which point "new directory(s)" seems to be a null. I'm not sure why it is behaving this way, I thought perhaps there are special rules because the recursion is in the constructor. Please help.</p>
  
  <pre><code>namespace AnalyzeDir
  {
      class directory
      {
          public string[] files;
          public ArrayList directories;
          public string mypath;
          public string myname;
  
          public directory(string mp)
          {
              mypath = mp;
              myname = mypath.Substring(mypath.LastIndexOf("\\"));
              files = Directory.GetFiles(mypath);
              fillDirectoriesRescursive();
          }
          public void fillDirectoriesRescursive()
          {
              string[] dirpaths = Directory.GetDirectories(mypath);
  
              if (dirpaths != null &amp;&amp; (dirpaths.Length &gt; 0))
              {
                  foreach(string s in dirpaths)
                  {
                          this.directories.Add(new directory(s));
                  }
              }
          }
  </code></pre>