C# object comparison

天涯浪子 提交于 2019-12-02 01:14:32

Overloading the == operator allows you to write x == y, which is much more natural than x.Equals(y), and will work even if x is null.

overloading operator == only improves the readability of your code. Always use .Equals() for the types you define, especially for deep object comparison.

System.String is the classic example of a reference type that benefits from a deep value equality comparison instead of a reference comparison.

In general, there are some circumstances where it makes code easier to write and the meaning of the equality is better expressed by a value comparison than by a reference comparison.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!