Skip to content

Simple LINQ Example

March 10, 2010

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);

}

}

}

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: