I am trying to arrange and output the elements of the list in specific order provided.
The original list is as follows:
var outcome = Result.ToArray()
The Result returns elements in format based on class signature as below:
class ResultOutcome {
public string id;
public string val;
}
so the outcome will have elements such as :
Result.ToArray()[0] = {id : "1", val: "100"}
Result.ToArray()[1] = {id : "2", val: "50"}
Result.ToArray()[2] = {id : "3", val: "75"}
Result.ToArray()[3] = {id : "4", val: "98"}
Result.ToArray()[4] = {id : "5", val: "100"}
etc.
I would like to arrange the outcome in the order where it is listed with ids in the order of
int requiredOrder [] = new int[5] {3,5,2,1,4}
so the outcome will be
Result.ToArray()[0] = {id : "3", val: "75"}
Result.ToArray()[1] = {id : "5", val: "100"}
Result.ToArray()[2] = {id : "2", val: "50"}
Result.ToArray()[3] = {id : "1", val: "100"}
Result.ToArray()[4] = {id : "4", val: "98"}
I have tried following given as per Ordering list by a specific order
var outcome = Result.ToArray();
int[] sequence = new int[5] { 3,4,1,2,5 };
Dictionary<int, int> sequence IndexedMap = Enumerable.Range(0, sequence .Length - 1).ToDictionary(r => sequence [r], r => r);
However, I am not sure how can I filter after it