Alex Rivera | Logout

Compare two objects and find the differences

Asked 2011-02-09T22:21:09.963
115

what is the best way to compare two objects and find the differences?

Customer a = new Customer();
Customer b = new Customer();
Edit
Report

1 Answer

14

The Equals method and the IEquatable<T> interface could be used to know if two objects are equal but they won't allow you to know the differences between the objects. You could use reflection by comparing each property values.

Yet another approach might consist into serializing those instances into some text format and compare the differences inside the resulting strings (XML, JSON, ...).

answered 2011-02-09T22:26:02.047

Your Answer