Created
November 7, 2019 08:24
-
-
Save divega/f0e9a22547c5f91ee6d581fca3e06e05 to your computer and use it in GitHub Desktop.
Sorting an array with the order of another array using LINQ's Join
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
using System; | |
using System.Linq; | |
namespace SortWithJoin | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var keys = new [] { 5, 7, 3, 2, 1, 4, 6, 9, 8 }; | |
var docs = new[] { (key: 1, val: "uno"), (key: 2, val: "dos"), (key:3, val:"tres") }; | |
var sorted = from key in keys | |
join doc in docs on key equals doc.key | |
select doc; | |
foreach(var doc in sorted) | |
{ | |
Console.WriteLine(doc); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output is