I have a list of events, each of which has a datetime property. I need to split the list up into sublists by year. The trick is, my list of events is pulled from a database and subject to change, so I can't just hardcode the set of years and sort the events into the right year. Is there a way that I can split my main list of events into sublists so that within each sublist, each event has the same year? So I would end up with a sublist of all 2010 events, a sublist of all 2011 events, and so on.
My list is created like this :
foreach (var ev in eventResults)
{
eventsList.Add(new Event()
{
Name = ev.Title,
Month = CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(ev.StartDate.Month),
Day = ev.StartDate.Day,
Year = ev.StartDate.Year
});
}