title: Order LINQ query elements by a collection of numbers
body: <p>This is a partially defined function that I'm using to retrieve the specified lines of a textfile, by passing the index of the lines I want:</p>
  
  <pre><code>Public Shared Function GetLines(ByVal sourceFilepath As String,
                                  ByVal lineNumbers As IEnumerable(Of Integer)) As IEnumerable(Of String)
  
      Return File.ReadAllLines(sourceFilepath, encoding).
                  Select(Function(line As String, index As Integer)
                              Return New With
                                     {
                                         Key .line = line,
                                         Key .index = index + 1
                                     }
                          End Function).
                  Where(Function(con) lineNumbers.Contains(con.index)).
                  OrderBy(Function(x) x.index.CompareTo(lineNumbers(x.index))).
                  Select(Function(con) con.line)
  
  End Function
  </code></pre>
  
  <p>Example usage:</p>
  
  <pre><code>GetLines("C:\file.txt", {1, 5, 6, 2} ' Linenumbers 1, 5, 6, and 2.
  </code></pre>
  
  <p>The problem is that I need to preserve the order of the lines, in the same order which I specified the indexes, so the function should order the query elements by that order {1, 5, 6, 2} but instead of that I get the lines in this order: {1, 2, 5, 6}.</p>
  
  <p>How can I fix the evaluation that I'm doing at the <code>OrderBy</code> extension to return the expected results?.</p>