Martin Martin - 8 months ago 66
C# Question

Compare the content of two objects for equality

I have two complex (i.e. objects with string, int, double, List and other home made data type) objects of the same type. I would like to compare the content of both of them to ensure that they are identical. Note: The object doesn't implement .Equals (I have no control on that) and doesn't implement IComparable.

Is there a generic way (reflection?) to compare the content of the two objects?

Thanks!

Answer Source

Is there a generic way to compare the content of the two objects?

Well yes, but generally that's known as the IComparable interface.

If you could descend from the class and create a child that implemented IComparable, that might be ideal.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download