Using IEqualityComparer<T> to determine uniqueness
<p>I am using a HashSet. I want to ensure that I don't have duplicate values. However, I am able to do so at the present moment.</p>

<pre><code>[Serializable()]
public class SafetyObsDS
{
    public int Count
    {
        get { return set.Count; }
    }

    HashSet&lt;CompResults&gt; set;

    public SafetyObsDS()
    {
        set = new HashSet&lt;CompResults&gt;(new CompareToComparer());
    }

    public bool Add(CompResults cr)
    {
        set.Remove(cr);
        return set.Add(cr);
    }

    public bool Remove(CompResults cr)
    {
        return set.Remove(cr);
    }

    [Serializable()]
    private class CompareToComparer : IEqualityComparer&lt;CompResults&gt; 
    {
        public CompareToComparer() {}

        public bool Equals(CompResults cr1, CompResults cr2) 
        {
            return (cr1.CompareTo(cr2) == 0);
        }

        public int GetHashCode(CompResults cr)
        {
            return (cr.SectionID);
        }
    }
}

[Serializable()]
public class CompResults : IComparable
{
    public int SectionID { get; set; }

    public ComResults(int sectID)
    {
        SectionID = sectID;
    }

    public int CompareTo(object obj)
    {
        return SectionID - (obj as CompResults).SectionID;
    }

}
</code></pre>

<p>I left the constructors and additional unnecessary code such as other fields out
When I perform the following operations, I receive undesired results:</p>

<pre>
Add(new CompResults(1));     Result: true
Add(new CompResults(1));     Result: true  &lt;--- this is a dup and I don't want it to add
Remove(new CompResults(1));  Result: true
</pre>

<p>thanks for your help in advance!</p>
