Last active
May 21, 2021 13:43
-
-
Save ppolyzos/c1b6681e3e04c0d1d928 to your computer and use it in GitHub Desktop.
C#: Sort one collection based on another
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Sort one collection based on keys defined in another | |
/// </summary> | |
/// <returns>Items sorted</returns> | |
public static IEnumerable<TResult> SortBy<TResult, TKey>( | |
this IEnumerable<TResult> itemsToSort, | |
IEnumerable<TKey> sortKeys, | |
Func<TResult, TKey> matchFunc) | |
{ | |
return sortKeys.Join(itemsToSort, | |
key => key, | |
matchFunc, | |
(key, iitem) => iitem); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment