I'm sorting with respect to Width
and Length
. However, Width
has the significance precedence, so Length
is only vital if Width
is exactly equal (both are integers). The comparison method I've implemented as shown below. Is this a neat trick with doubling the most significant value's comparer or is there a better way?
List<Thing> things = thingsDictionary.Select(thing
=> thing.Value).ToList();
things.Sort((first, second)
=> 2 * first.Width.CompareTo(second.Width)
+ first.Length.CompareTo(second.Length));
Width
a property or a method? I'm confused byfirst.Width(second.Width)
– dcastro Nov 18 '14 at 10:36things
,thingsDictionary
andfirst
. This doesn't give any meaning to the variable. Plus, give the datastructure for the classThing
. This looks like pseudo-code and is not fit for reviewing! – Abbas Nov 18 '14 at 10:42Thing
..... – RubberDuck Nov 18 '14 at 13:27