title: Parsing text file containing hierarchical items using linq
body: <p>I'm rewriting some code and trying to use Linq whenever I can. My problem right now is a simple file import function.</p>
  
  <p>The file basically looks like this:</p>
  
  <pre><code>A1
  B1|1882
  C1|7315808907578
  B9
  B1|1883
  C1|4025595431639
  C1|8717734091786
  C1|8717734091809
  C1|8717734098280
  C1|8717795041874
  C1|8717795060998
  C1|8717795108973
  B9
  B1|1884
  C1|4025595732071
  C1|7315808887184
  C1|8717734001983
  B9
  A9
  </code></pre>
  
  <p>The existing code looks like this:</p>
  
  <pre><code>line = reader.ReadLine();
  string itemNo = "";
  List&lt;AltItems&gt; list = new List&lt;AltItems&gt;();
  while (line != null) {
      posts = line.Split(postSep);
      if (posts.Length == 0) { }
      else if (posts[0].Equals("A1")) { }
      else if (posts[0].Equals("B1"))
          itemNo = posts[1];
      else if (posts[0].Equals("C1")) {
          string altItemNo = posts[1];
          list.Add(new AltItems() { ItemNo = itemNo, AltItemNo = altItemNo });
      }
      line = reader.ReadLine();
  }
  </code></pre>
  
  <p>What would the equivalent Linq query look like? Any thoughts about performance penalties rewriting this code using Linq? I also have files with multiple  hierarchical levels where data from items on the first level is needed to build up items on the third level...</p>