Self referential class : <p>Trying to write a class for a directory which can have a parent and a list of children.</p>

<p>Class definition:</p>

<pre><code>class Directory {
    public string name;
    public Directory parentDir;
    public List&lt;Directory&gt; subDirs;

    public Directory(string name) {
        this.name = name;
    }

    public void addSubDir(Directory x) {
        subDirs.Add(x);
    }
}
</code></pre>

<p>Sample code trying to create two instances and set one as a child of the other:</p>

<pre><code>Directory temp1 = new Directory("root");

Directory temp2 = new Directory("games");

temp1.addSubDir(temp2);
</code></pre>

<p>The error I get is: </p>

<pre><code>System.NullReferenceException was unhandled
  Message=Object reference not set to an instance of an object.
</code></pre>
