-
Notifications
You must be signed in to change notification settings - Fork 231
Working with collections of calendar events
Rian Stockbower edited this page Nov 24, 2017
·
3 revisions
var relevantEvents = bigCalendar.GetOccurrences(start, end)
.Select(o => o.Source)
.Cast<CalendarEvent>()
.Distinct()
.ToList();
var smallerCalendar = new Calendar();
smallerCalendar.Events.AddRange(relevantEvent);
Incidentally, if you need to do something like this in your application, you may wish to read the concurrency page for information on how to spread the work across all your CPU cores.
The easiest way to do this is to create a HashSet<CalendarEvent>
for each collection, and do set comparisons.
Suppose oldCollection
contains some number of CalendarEvent
s. newCollection
contains all of the CalendarEvent
s in oldCollection
, plus a few more. You want to find the new events that have been added:
var completeSet = new HashSet<CollectionEvent>();
completeSet.UnionWith(newCollection); // Add the new events
completeSet.ExceptWith(oldCollection); // Subtract the old
This will leave you with only the CalendarEvent
s that have been added since oldCollection
was written down.