Split list into sublists based on a value of a certain property?

You need to make a grouping by year like this:

eventsList.GroupBy(x => x.Year)

So later you will be able to iterate through result of code above:

foreach (var eventsInYear in eventsList.GroupBy(x => x.Year))
{
    // eventsInYear.Key - year
    // eventsInYear - collection of events in that year
}

Leave a Comment