Why was Equals() and == designed to be different?
This question is not about the differences between ==
and Equals
. It's about why they were designed different.
We know the differences causes many problems, which must have been pretty easy to spot up front:
Equals
and ==
yield different results for two instances of the same entity. ==
yield different results when comparing subclasses, because ==
is not polymorphic The short answer is that the C# language design team and the .NET framework design team couldn't agree on how best to compare values/objects for equality, so each implemented their own system.
For a more technical, detailed answer, please refer to a blog post on the subject by Eric Lippert.
链接地址: http://www.djcxy.com/p/26484.html