I have
List<string> strs;
double[] values;
where the values array contains the value of each of the string in strs list
Say strs={"abc","def","ghi"}
and values={3,1,2}
this means “abc” has value 3 and so on.
I wish to sort strs and values ordered by values, such that it becomes
strs={"def","ghi","abc"}
values={1,2,3}
Is there any easy way to achieve this?
The
Array.Sortmethod has an overload that takes two arrays and sorts both arrays according to the values in the first array, so make an array out of the list:Then sorting them can’t be simpler:
And then back to a list, if you need that: