Suppose I do something like
var Ordered = MyList.OrderBy(x => x.prop1).ThenBy(x => x.prop2);
Does MyList.OrderBy(x => x.prop1) filtered list, and then does it additionally filter this ThenBy(x => x.prop2) list ThenBy(x => x.prop2) ? In other words, is this equivalent
var OrderedByProp1 = MyList.OrderBy(x => x.prop1); var Ordered = OrderedByProp1.OrderBy(x => x.prop2);
???
Because, obviously, this can be optimized by executing the sorting algorithm with a comparator:
var Ordered = MyList.Sort( (x,y) => x.prop1 != y.prop1 ? x.prop1 < y.prop1 : ( x.prop2 < y.prop2 ) );
If he does some kind of optimization, and the intermediate lists are not returned in the process, then how does he know how to do this? How do you write a class that optimizes method chains on itself? No difference.
source share