比较两个对象。 [英] Comparing two objects .

查看:145
本文介绍了比较两个对象。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个复杂的对象,什么是写code来比较两个实例,看看他们是相同的最佳实践模式

If i have a complex object, what is the best practice pattern to write code to compare 2 instances to see if they are the same

推荐答案

实施IEquatable接口。这个定义的值类型或类实现以确定实例的创建平等的一种特定类型,方法的通用方法。不要忘了重载Equals(对象),以及。
点击此处了解详情:

Implement the IEquatable interface. This defines a generalized method that a value type or class implements to create a type-specific method for determining equality of instances. Don't forget to override Equals(object) as well. More information here:

<一个href=\"http://msdn.microsoft.com/en-us/library/ms131187.aspx\">http://msdn.microsoft.com/en-us/library/ms131187.aspx

这篇关于比较两个对象。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆