Simple LINQ Example
I’m working on a rather large WPF app and there are bunch of little bits and bobs that I’ve noticed might be of interest or at least a nice reference for myself. Here is one where I’m updating a user’s profile. During the process I’m creating a bit that schedules some tasks for users. I have a static method that updates the users settings but I needed a way to make sure that I was getting rid of days they’d unchecked in addition to adding the new ones. Heres how I checked to see what days they may have removed.
if(oldProfile != null) if
{
List<DaysOfTheWeek> removedDays = oldProfile.DaysToWake.Keys.Except(profile.DaysToWake.Keys).ToList<DaysOfTheWeek>();
if (removedDays.Count > 0)
{
foreach (DaysOfTheWeek removedDay in removedDays)
{
TaskScheduleHelper.DeleteTask(profile.ProfileName, removedDay);
}
}
}
(oldProfile != null)
{
List<DaysOfTheWeek> removedDays = oldProfile.DaysToWake.Keys.Except(profile.DaysToWake.Keys).ToList<DaysOfTheWeek>();
if (removedDays.Count > 0)
{
foreach (DaysOfTheWeek removedDay in removedDays)
{
TaskScheduleHelper.DeleteTask(profile.ProfileName, removedDay);
}
}
}