public void Compare2(CompareTestA A, CompareTestB B) { if (A.Equals(B)) { //Equals } }
public void Compare1(CompareTestA A, CompareTestB B) { //Never: if (A == B) { } if ((object)A == (object)B) { //Equals } }
public override bool Equals(object obj) { CompareTestA A_1 = (CompareTestA)obj; //Be careful! CompareTestA A = obj as CompareTestA; if (A != null) { return(A.MyProperty == this.MyProperty); } return(base.Equals(obj)); }