I need to sort one list (string) according to another list values (int) from the smallest to the highest int. Possibility to have several times the same string.
For example:
List<string> list1= new List<string>() { "abc", "xyzz", "abc", "fgh", "abc" };
List<int> list2 = new List<int>() { 8, 15, 4, 2, 22 };
output:
list1 {"fgh","abc", "abc", "xyzz", "abc"}
This line should probably work but I still miss something:
list1 = list1.OrderBy(d => list2."i miss something here".ToList());
list1.Select((x, i) => (Item: x, Index: i)).OrderBy(t => list2[t.Index]).Select(t => t.Item).ToList()ought to work. In any case, see duplicates...there are lots of examples on the site already you can draw from.Zip