title: Two-way synchronization between lists
body: <p>I hope someone here can help me with this problem that's been giving me a headache.</p>
  
  <p>If I have two lists of custom objects, is there any way (using LINQ or otherwise) to performance-efficiently synchronize them? Performance matters because there could conceivably be a very large amount of objects in the lists.</p>
  
  <p>I need to check for new or deleted items on one list - I assume here that one list is master and only allow <strong>new</strong> objects to be added there or objects to be outright deleted so this doesn't seem too hard.</p>
  
  <p>But I also need to synchronize changes made to <strong>either</strong> list based on a timestamp (newest takes precedence).</p>
  
  <p>Code example:</p>
  
  <pre><code>public class CalendarItem
  {
      public CalendarItem(int id, string subject, string content, DateTime lastUpdated, DateTime startTime, DateTime endTime)
      {
          Id = id;
          Subject = subject;
          Content = content;
          LastUpdated = lastUpdated;
          StartTime = startTime;
          EndTime = endTime;
      }
  
      public int Id { get; }
      public DateTime LastUpdated { get; }
      public string Subject { get; }
      public string Content { get; }
      public DateTime StartTime { get; }
      public DateTime EndTime { get; }
  }
  </code></pre>
  
  <p>Then I want to be able to do something like the following setup:</p>
  
  <pre><code>var time = DateTime.Now;
  
  var itemIdentical1 = new CalendarItem(1, "Item Identical On Both Lists", "", time, DateTime.Now, DateTime.Now);
  var itemIdentical2 = new CalendarItem(1, "Item Identical On Both Lists", "", time, DateTime.Now, DateTime.Now);
  
  var itemBeforeUpdate1 = new CalendarItem(2, "Item On List 1 Will Be Changed", "", time, DateTime.Now, DateTime.Now);
  var itemUpdated1 = new CalendarItem(2, "Item on List 1 Changed", "", time.AddMinutes(15), DateTime.Now, DateTime.Now);
  
  var itemBeforeUpdate2 = new CalendarItem(3, "Item On List 2 Will Be Changed", "", time, DateTime.Now, DateTime.Now);
  var itemUpdated2 = new CalendarItem(3, "Item on List 2 Changed", "", time.AddMinutes(15), DateTime.Now, DateTime.Now);
  
  var itemBeforeUpdate3 = new CalendarItem(4, "More Item On List 2 Will Be Changed", "", time, DateTime.Now, DateTime.Now);
  var itemUpdated3 = new CalendarItem(4, "More Item on List 2 Changed", "", time.AddMinutes(15), DateTime.Now, DateTime.Now);
  
  var list1 = new List&lt;CalendarItem&gt; { itemIdentical1, itemUpdated1, itemBeforeUpdate2, itemBeforeUpdate3 };
  var list2 = new List&lt;CalendarItem&gt; { itemIdentical2, itemBeforeUpdate1, itemUpdated2, itemUpdated3 };
  </code></pre>
  
  <p>Then here we should have the magic step I'm missing in order to get the following:</p>
  
  <pre><code>var listOfItemsToUpdateOnList1 = List { itemUpdated2, itemUpdated3 };
  var listOfItemsToUpdateOnList2 = List { itemUpdated1 };
  </code></pre>