I have a serial of object defined as:
public class Foo
{
public DateTime Time {get;set;}
}
now I want to group objects(IEnumerable<Foo>) according to the time, e.g. I want to group them according to hour or day or month.
for example (group into hour):
group 1(13:00-14:00) : foo1, foo2, foo3
group 2(14:00-15:00): foo4, foo5
How to write LINQ over this? hope I made myself clear.
If you don’t want to group the 13-14hr yesterday with the 13-14hr today, nor the 5th of this month with the 5th of last month etc. so you’ll need to do something like:-
If you really do want to map all of the same hour/day/month into the same group then it’s easier.