title: how does except method work in linq
body: <p>I have the classes:</p>
  
  <pre><code>class SomeClass
  {
     public string Name{get;set;}
     public int SomeInt{get;set;}
  }
  
  
  class SomeComparison: IEqualityComparer&lt;SomeClass&gt;
  {
       public bool Equals(SomeClass s, SomeClass d)
       {
           return s.Name == d.Name;
       }
  
       public int GetHashCode(SomeClass a)
       {
           return (a.Name.GetHashCode() * 251);
       }
  }
  </code></pre>
  
  <p>I also have two large <code>List&lt;SomeClass&gt;</code> called <code>list1</code> and <code>list2</code></p>
  
  <p>before I used to have:</p>
  
  <pre><code> var q = (from a in list1
           from b in list2
           where a.Name != b.Name
           select a).ToList();
  </code></pre>
  
  <p>and that took about 1 minute to execute. Now I have:</p>
  
  <pre><code>var q =  list1.Except(list2,new SomeComparison()).ToList();
  </code></pre>
  
  <p>and that takes less than 1 second!  </p>
  
  <p>I will like to understand what does the Except method do. Does the method creates a hash table of each list and then perform the same comparison? If I will be performing a lot of this comparisons should I create a Hashtable instead? </p>
  
  <hr>
  
  <h2>EDIT</h2>
  
  <p>Now instead of having lists I have two <code>HashSet&lt;SomeClass&gt;</code> called  <code>hashSet1</code> and <code>hashSet2</code></p>
  
  <p>when I do:</p>
  
  <pre><code>   var q = (from a in hashSet1
             form b in hashSet2
             where a.Name != b.Name
             select a).ToList();
  </code></pre>
  
  <p>that still takes a long time... What am I doing wrong?  </p>