Comparing two objects and returning the differences
<p>I have to run comparisons between thousands of pairs of objects, and then perform actions depending on the differences.</p>

<p>Is there an "accepted" way of doing this?</p>

<pre><code>class ObjectA
{
    public string FieldA { get; set; }
    public string FieldB { get; set; }
    public string FieldC { get; set; }
}

class ObjectB
{
    public string FieldA { get; set; }
    public string FieldB { get; set; }
    public string FieldC { get; set; }

    public bool Equals(ObjectA obj)
    {
        if ((object)obj == null) return false;
        if (this.FieldA != obj.FieldA) return false;
        if (this.FieldB != obj.FieldB) return false;
        if (this.FieldC != obj.FieldC) return false;
        return true;            
    }
}

void test()
{
    ObjectA a = new ObjectA();
    ObjectB b = new ObjectB();
    if (b.Equals(a))
    {
         Console.WriteLine("Same!!");
    }
}
</code></pre>

<p>That does a fairly simple test to determine if <code>b=a</code>, but I also want to know what is different between them.</p>

<p>Should I add a <code>differences()</code> method that returns a list of properties?  That seems a bit <em>not.net</em> though, as then I'll be bandying about strings.</p>

<pre><code>public List&lt;string&gt; Differences(ObjectA obj)
{
    List&lt;string&gt; differences = new List&lt;string&gt;();
    if ((object)obj == null)
    {
        differences.Add("null");
    }
    else
    {
        if (this.FieldA != obj.FieldA) differences.Add("FieldA");
        if (this.FieldB != obj.FieldB) differences.Add("FieldB");
        if (this.FieldC != obj.FieldC) differences.Add("FieldC");
    }
    return differences;
}
</code></pre>

<p>Also that seems much slower than the first, as I would be creating all those <code>List&lt;string&gt;</code>, and not short-cutting the comparisons.  Or is that just the price I pay for having the extra information?</p>
