==主场迎战的Object.Equals(对象)的.NET主场、对象、Equals、Object

2023-09-02 01:29:16 作者:孤浪 .

所以,当我还是一个比较初级的新手,我现在,我常想,这两样东西都是语法糖对方,即,使用了另一种只是一个个人的preference。随着时间的推移,我来找这两个是不一样的事情,即使在默认的实现(见的这个和的这个)。为了进一步迷惑的事情,每个人都可以被重写/重载分别有完全不同的含义。

So, when I was a comparative novice to the novice I am right now, I used to think that these two things were syntactic sugar for each other, i.e. that using one over the other was simply a personal preference. Over time, I'm come to find that these two are not the same thing, even in a default implementation (see this and this). To further confuse the matter, each can be overridden/overloaded separately to have completely different meanings.

这是一件好事,有什么区别,而在其他时候/你为什么要使用它?

Is this a good thing, what are the differences, and when/why should you use one over the other?

推荐答案

MSDN有两种事情说清楚和固体的说明。

MSDN has clear and solid descriptions of both things.

的Object.Equals方法

==操作符

重载操作

指引()和operator ==

这是一件好事,有什么   差异,当/为什么要   使用一个比其他?

Is this a good thing, what are the differences, and when/why should you use one over the other?

岂是好或坏的东西?一 - 方法,另一种 - 运营商。如果参考平等是不够的,他们超载,否则保持这些设置。对于基本数据类型,他们只是工作开箱。

How can it be "good" or "bad" thing? One - method, another - operator. If reference equality is not sufficient, overload them, otherwise leave them as is. For primitive types they just work out of box.