Please note to the following topic that has already been raised :
I want to sort a list by another list. I add to the list with the following command :
ListClass.Add(new item_util(items[b], util[b]));
Now based on the above topic , I can sort items by ascending :
List<item_util> SortedList = ListClass.OrderBy(o=>o.items).ToList();
I do not want to sort ascending. How can I sort items by another list (ListA)?
Updated
int[] items = {7, 4, 1};
int[] util = {5, 11, 20};
var listA = new List<int> {5, 4, 1, 2, 7, 3, 8, 6};
List<item_util> ListClass= new List<item_util>();
for (int b = 0; b < items.Length; b++)
ListClass.Add(new item_util(items[b], util[b]));
List<item_util> SortedList = ListClass.OrderBy(o => o.item).ToList();
Currently SortedList
output is equal to: {(1,20),(4,11),(7,5)}
But I want to sort the list acording to listA. So the output must be obtained as : {(4, 11), (1, 20), (7, 5)}
Because they are arranged in ListA as : {5, 4, 1, 2, 7, 3, 8, 6}