I’m using LINQ in C#
This code result in dates of type Lookup<TKey, TElement>
var dates = timetableEvents.GroupBy(x => x.DateTimeStart);
I need instead just a list of DateTimeStart (of type DateTime).
How should I change my LINQ expressions?
Simply use
Selectinstead:Or if you just want one from each group:
And if you want it to run a little bit faster, then you can use Distinct (as in Rawling’s answer), but you probably won’t notice much difference, unless you have a lot objects (though, the intention is much cleaner):
I find this site very useful when trying to learn LINQ: 101 LINQ Samples