My opinion is that this is a case where using Linq ... while perhaps possible ... is probably "over-kill" because: what you are really doing is quite
arbitrary. If I understand your goal, it is to move entries in a query result that match entries in another list to the front of the query result.
For the case that your query result
doesn't contain duplicate values, you can use something like this:
private List<int> queryList = new List<int> {11, 42, 65, 33, 3, 5, 65, 5, 8};
private List<int>sortByList = new List<int> {65, 123, 42, 11};
int sortByInt;
int matchAt;
for (int i = sortByList.Count - 1; i >= 0; i--)
{
sortByInt = sortByList[i];
if (queryList.Contains(sortByInt))
{
matchAt = queryList.IndexOf(sortByInt);
queryList.RemoveAt(matchAt);
queryList.Insert(0, sortByInt);
}
}
That would handle the case of having entries in the sort-by list that do not occur in the query list.