且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

比较两个对象是否相等的内容

更新时间:2022-10-14 19:49:49


  

    

有两个对象的内容比较通用的方法是什么?


  块引用>
块引用>

嗯,是的,但普遍认为的被称为IComparable接口。

如果你可以从类下降,并创建一个孩子说实现IComparable的,这可能是理想的。

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!

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.