title: LINQ - Find "path" along Legs
body: <p>Suppose I have simple "leg" Class defined by two points (actually PointIDs):</p>
  
  <pre><code>public class Leg
  {
      public int p1Id;
      public int p2Id;
  }
  </code></pre>
  
  <p>List of Legs are "interconnected", on the way that pt2 of one leg is same as pt1 of another leg (except first and last one). Let's initialize simple list:</p>
  
  <pre><code>var legs = new List&lt;Leg&gt;();
  
  var l1 = new Leg { p1Id = 1, p2Id = 2 };
  var l2 = new Leg { p1Id = 4, p2Id = 5 };
  var l3 = new Leg { p1Id = 2, p2Id = 3 };
  var l4 = new Leg { p1Id = 5, p2Id = 6 };
  var l5 = new Leg { p1Id = 3, p2Id = 4 };
  
  legs.Add(l1);
  legs.Add(l2);
  legs.Add(l3);
  legs.Add(l4);
  legs.Add(l5);
  </code></pre>
  
  <p>Fact is that this list of legs is not sorted, and of course IDs are not consecutive, like it is the case in this example.</p>
  
  <p>Question is how to create function which will return list of consecutive points, between two given points, so:</p>
  
  <pre><code>var myLegs = FindMyLegs(legs, 5, 2);
  </code></pre>
  
  <p>.. should return following list : 5, 4, 3, 2</p>
  
  <p>I guess it might be done by LINQ and inner join list of legs twice (legs1.pt2Id == legs2.pt1Id), but I am really not experienced in LINQ, and I can not find right way.</p>
  
  <p>Basically I'll need some function:</p>
  
  <pre><code>List&lt;int&gt; FindMyLegs(List&lt;Leg&gt; allLegs, int startPt, int endPt) { ??? }
  </code></pre>