比较两个对象是否相等的内容 [英] Compare the content of two objects for equality
问题描述
我有两个复杂的同类型的对象(即用字符串,整数,双,单等自制数据类型的对象)。我想两者的内容相比较,以确保它们是相同的。注:该对象未实现.Equals(我有没有控制)和未实现IComparable。
有没有一种通用的方法(反射?)两个对象的内容进行比较?
谢谢!
的有两个对象的内容比较通用的方法是什么?的
块引用>
块引用>嗯,是的,但普遍认为的被称为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.
这篇关于比较两个对象是否相等的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!