title: Intersect with a custom IEqualityComparer using Linq
body: <p>Long story short: I have 2 collections of objects. One contains good values (Let's call it "Good"), the other default values (Mr. "Default"). I want the Intersect of the Union between Good and Default, and Default. In other words: Intersect(Union(Good, Default), Default). One might think it resolves as Default, but here is where it gets tricky : I use a custom IEqualityComparer.</p>
  
  <p>I got the following classes :</p>
  
  <pre><code>class MyClass
  {
      public string MyString1;
      public string MyString2;
      public string MyString3;
  }
  
  class MyEqualityComparer : IEqualityComparer&lt;MyClass&gt;
  {
      public bool Equals(MyClass item1, MyClass item2)
      {
          if(item1 == null &amp;&amp; item2 == null)
              return true;
          else if((item1 != null &amp;&amp; item2 == null) ||
                  (item1 == null &amp;&amp; item2 != null))
              return false;
  
          return item1.MyString1.Equals(item2.MyString1) &amp;&amp;
                 item1.MyString2.Equals(item2.MyString2);
      }
  
      public int GetHashCode(MyClass item)
      {
          return new { item.MyString1, item.MyString2 }.GetHashCode();
      }
  }
  </code></pre>
  
  <p>Here are the characteristic of my collections Good and Default collections :</p>
  
  <p>Default : It's a large set, containing all the wanted { MyString1, MyString2 } pairs, but the MyString3 values are, as you can guess, default values.</p>
  
  <p>Good : It's a smaller set, containing mostly items which are in the Default set, but with some good MyString3 values. It also has some { MyString1, MyString2 } that are outside of the wanted set.</p>
  
  <p>What I want to do is this : Take only the items from Good that are in Default, but add the other items in Default to that.</p>
  
  <p>Here is, what I think is, my best try :</p>
  
  <pre><code>HalfWantedResult = Good.Union(Default, new MyEqualityComparer());
  WantedResult= HalfWantedResult.Intersect(Good, new MyEqualityComparer());
  </code></pre>
  
  <p>I taught it should have worked, but the result I get is basically only the good { MyString1, MyString2 } pairs set, but all coming from the Default set, so I have the default value all across. I also tried switching the Default and Good of the last Intersect, but I get the same result.</p>