Preserve order of values with linq and ToLookup()
linq
Solution
The current implementation of `ToLookup()` does indeed preserve the order of the values (check the implementation of `Lookup<TKey,TElement>.Grouping<TKey,TElement>.Add()`), but I do not believe it is guaranteed to stay that way. To guarantee ordering, your best bet is probably to include the element's original index, perhaps using `Select`'s with-index overload, and then sort again.
Problem
While I'm pretty certain that the keys are unordered when returned from linq's ToLookup method, Is the order of values preserved? I can't find any documentation that says one way or the other.