✅ Struggling to use custom comparer with a list of KeyValuePairs
I'm trying to sort a list of keyvaluepairs on the key. I've defined an IComparer using Comparer.Create, but the list after sorting is identical to before. I can't use a SortedList because that requires unique keys.
The output looks like
Whereas I'd expect it to be sorted in either ascending or descending order.
5 Replies
You could just
OrderBy()
itAngius
REPL Result: Success
Result: OrderedEnumerable<KeyValuePair<float, int>, float>
Compile: 414.906ms | Execution: 56.561ms | React with ❌ to remove this embed.
Thank you
btw,
a.Key < b.Key ? 1 : 0
is seems to be wrong.
a negative value idicates that a
is smaller,
zero indicates that they are equal,
and a positive value indicates that a
is bigger.ah, thanks
just tried both of those and they both work, thank you both