Finding Differences In Sets
<p>I have this  class (a partial listing):</p>

<pre><code>class CiscoSwitch 
{
  private string _SwitchName = string.Empty;
  public SwitchName {get {return _SwitchName;} set{_SwitchName=value; }}
}
</code></pre>

<p>I have 2 lists of CiscoSwitch objects. I am trying to compare them to pick out the ones that are not duplicates. I only want the duplicates.  I tried a Lambda expression but got a compiler error that CiscoSwitch was a non-delgate type.   </p>

<p>I am now wondering about something like this - it would allow me to use the List.Except() method (I think):</p>

<pre><code>static class SwitchComparer
{ 
  static bool CompareSwitchNames(CiscoSwitch s1, CiscoSwitch s2)
         {
            if (sw1.SwitchName == s2.SwitchName) {return true;}
             else {return false;}
         }
}

     // to find the differences 
 // this is a method of the CiscoSwitchClass
private List&lt;CiscoSwitch&gt; FindDifferences(List&lt;CiscoSwitch&gt; List1, List&lt;CiscoSwitch&gt; List2)
{
       return List1.Except(List2, SwitchComparer.CompareSwitchNames();
 }
</code></pre>

<p>this could also be done with a foreach but I think this way is a lot cleaner, if it is correct.  I am also thinking there are other attributes of a CiscoSwitch I might want to compare some day so could add methods to the SwitchComparer class as I need them. </p>
