I have two lists { 7 3 5 }
and {9 8 1}
.
I want to sort my first list and I want the second list to have the same index permutation as given by the first list.
{3 5 7}
=> {8 1 9}
Is it possible to do this in a single LINQ statement?
Sounds like you might want:
var list1 = new List<int> { 7, 3, 5 }; var list2 = new List<int> { 9, 8, 1 }; var orderedZip = list1.Zip(list2, (x, y) => new { x, y } ) .OrderBy(pair => pair.x) .ToList(); list1 = orderedZip.Select(pair => pair.x).ToList(); list2 = orderedZip.Select(pair => pair.y).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With