I'm trying to combine a number of List<T> where T:IGetTime
(i.e T
will always have method getTime()
).
Then I'm trying order the items by the DateTime
that getTime()
returns.
My LINQ looks like this:
public static List<T> Combine(List<T> one, List<T> two, List<T> three) { var result = from IGetTime item in one from IGetTime item2 in two from IGetTime item3 in three select new{ item, item2, item3 }; return result.ToList(); }
I've yet to add an orderby
. Which should look somthing like this:
var thestream = from T item in this orderby item.getTime() descending select item;
Is there anyway to both combine and order the final list????
Thanks in advance,
Roberto
You've got three lists here - what exactly are you trying to order by?
Your cast is incorrect too - the result will be an IEnumerable<X>
where X
is an anonymous type with three T
s in.
If the idea is really to concatenate the three lists and then sort, you want:
return one.Concat(two) .Concat(three) .OrderByDescending(x => x.GetTime()) .ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With