title: how to use a tree data structure in C#
body: <p>I found an implementation for a tree at <a href="https://stackoverflow.com/questions/66893/tree-data-structure-in-c">this SO question</a>. Unfortunately I don't know how to use it. Also I made a change to it since LinkedList does not have Add method:</p>
  
  <pre><code>delegate void TreeVisitor&lt;T&gt;(T nodeData);
  
  class NTree&lt;T&gt;
  {
      T data;
      List&lt;NTree&lt;T&gt;&gt; children;
  
      public NTree(T data)
      {
          this.data = data;
          children = new List&lt;NTree&lt;T&gt;&gt;();
      }
  
      public void AddChild(T data)
      {
          children.Add(new NTree&lt;T&gt;(data));
      }
  
      public NTree&lt;T&gt; GetChild(int i)
      {
          return children[i];
      }
  
      public void Traverse(NTree&lt;T&gt; node, TreeVisitor&lt;T&gt; visitor)
      {
          visitor(node.data);
          foreach (NTree&lt;T&gt; kid in node.children)
              Traverse(kid, visitor);
      }
  }
  </code></pre>
  
  <p>I have class named tTable and I want to store it's children and their grandchildren (...) in this tree. My need is to find immediate children and not traverse entire tree. I also might need to find children with some criteria. Let's say tTable has only name and I want to find children with names matching some criteria. tTables constructor gives name a value according to int-value (somehow).</p>
  
  <p>How do I use Traverse (write delegate) if I have code like this;</p>
  
  <pre><code>int i = 0;
  Dictionary&lt;string, NTree&lt;tTable&gt;&gt; tableTreeByRootTableName = 
                    new Dictionary&lt;string, NTree&lt;tTable&gt;&gt;();
  tTable aTable = new tTable(i++);
  tableTreeByRootTableName[aTable.Name] = new NTree(aTable);
  tableTreeByRootTableName[aTable.Name].AddChild(new tTable(i++));
  tableTreeByRootTableName[aTable.Name].AddChild(new tTable(i++));
  
  tableTreeByRootTableName[aTable.Name].GetChild(1).AddChild(new tTable(i++));
  </code></pre>