I have 2 list objects, one is just a list of ints, the other is a list of objects but the objects has an ID property.
What i want to do is sort the list of objects b
Here is an extension method which encapsulates Simon D.'s response for lists of any type.
public static IEnumerable SortBy(this IEnumerable sortItems,
IEnumerable sortKeys,
Func matchFunc)
{
return sortKeys.Join(sortItems,
k => k,
matchFunc,
(k, i) => i);
}
Usage is something like:
var sorted = toSort.SortBy(sortKeys, i => i.Key);