title: Looking for a faster way of searching for a property in a List of classes
body: <p>Below is the class I'm using to represent a tree structure, for displaying files and folders of a game's archive format. </p>
  
  <pre><code>public class DirNode : INotifyPropertyChanged
  {
       public String Name { get; set; }
       public int Index { get; private set; }
       public int FileIndex { get; private set; }
       public int Type { get; private set; }
       public List&lt;DirNode&gt; Directories { get; set; }
       public List&lt;FileNode&gt; Files { get; set; }
  
       public DirNode(String n, int index, int type, int fi)
       {
             Name = n;
             Directories = new List&lt;DirNode&gt;();
             Files = new List&lt;FileNode&gt;();
             Index = index;
             Type = type;
             FileIndex = fi;
       }
  }
  </code></pre>
  
  <p>Below is a method of the class that I'm currently using to parse path strings into the tree. It worked well enough when I was only loading one archive, but when trying to "mount" multiple archives, the inefficiency certainly shows</p>
  
  <pre><code> public void AddPath(String[] path, int index, int fileIndex)
          {
              if (path.Length &gt; 1) //It's a Folder;
              {
                  bool found = false;
                  int i = 0;
                  while (i &lt; this.Directories.Count &amp;&amp; found == false)//search to see if this folder already exists
                  {
                      if (this.Directories[i].Name == path[0])
                      {
                          found = true;
                          String[] newPath = new String[path.Length - 1];
                          Array.Copy(path, 1, newPath, 0, newPath.Length);
                          this.Directories[i].AddPath(newPath, index,fileIndex);
                          return;
                      }
  
                      i++;
                  }
                  if (found == false) //new item
                  {
                      DirNode dn = new DirNode(path[0], -1, 0,fileIndex);
                      this.Directories.Add(dn);
                      String[] newPath = new String[path.Length - 1];
                      Array.Copy(path, 1, newPath, 0, newPath.Length);
                      this.Directories[this.Directories.Count - 1].AddPath(newPath, index,fileIndex);
                  }
              }
              else if (path.Length == 1) //a file!
              {
                  DirNode fn = new DirNode(path[0], index, 1,fileIndex);
                  this.Directories.Add(fn);
                  return;
              }
              else
              {
                  //really no reason why we should be here. 
                  return;
              }
          }
  </code></pre>
  
  <p>I know BinarySearch requires a pre-sorted list, which won't work, as the lists aren't sorted until after the tree is assembled. But it is, ultimately sorted, so a Hash won't work either. If anybody has any ideas, I'd love to hear them. </p>
  
  <p>Of course, if anybody knows of a virtual implementation of the .NET DirectoryInfo class, that would likely even be better. </p>