I would like to work with ordered enumerables, and use interfaces as return types rather than the concrete types. I need to return an ordered set of objects. Bu
How could List
implement IOrderedEnumerable
? It would have to provide a way of creating a subsequent ordering... what does that even mean?
Consider this:
var names = new List { "Jon", "Holly", "Tom", "Robin", "William" };
var ordered = names.ThenBy(x => x.Length);
what does that even mean? There's no primary sort order (as there would be if I used names.OrderBy(x => x)
), so it's impossible to impose a secondary sort order.
I suggest you try creating your own implementation of IOrderedEnumerable
based on a List
- as you attempt to implement the CreateOrderedEnumerable
method, I think you'll see why it's inappropriate. You may find my Edulinq blog post on IOrderedEnumerable