I have this dictionary
Dictionary<string, List<double[]>> dictionary = new Dictionary<string, List<double[]>>();
I filled it with a lot of data.
each array in the list has two values like this:
[xvalue, yvalue]
Is there anyway so I can sort each list in the dictionary depending on the xvalue of the arrays.
This is the list
[[1,100], [10, 100], ....[3, 100]]
[[1,100], [3,100], [10,100]]
To be honest, All I did is google searching for such a feature but I couldn't do more than that because I am not that good in c# and I thought asking you would save a lot of time.
Iterate over all element of the dictionary and sort each of the lists. You can sort a list by calling List.Sort with a proper comparison function.
foreach(var entry in dictionary) {
entry.Value.Sort((a, b) => a[0].CompareTo(b[0]));
}
Try this code:
foreach (var pair in dictionary)
{
pair.Value.Sort((x, y) => x[0].CompareTo(y[0]));
}
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