3 ms·
The LINQ really is much more succint, but the original code did not set the bar very high. Why should one write a 12 line comparing function when using 'b.value
by lubomir 13y ago
The LINQ really is much more succint, but the original code did not set the bar very high. Why should one write a 12 line comparing function when using 'b.value - a.value' would work pretty much the same (unless C# really requires comparison to return -1/1 instead of any negative/positive integer, which would be fixed by a sign function).
- ajanuary 13y agoOr do: private static int CompareKVPByCount(KeyValuePair<string, int> a, KeyValuePair<string, int> b) { return a.Value.Compare(b.Value); } Or even: kvpList.Sort(kvp => kvp.Value) But that would probably be straying into authors "list of language features I've completely ignored for the last 5 years"