Replace IEqualityComparer with "==" interface #7641
Replies: 4 comments 2 replies
-
I'm not sure what you mean by "replace". It's not like the runtime can remove those interfaces, as too many other classes depend on them. I'd suggest that |
Beta Was this translation helpful? Give feedback.
-
I'm not really understanding what the concrete suggestion is here at the language level. Could you flesh it out a bit? |
Beta Was this translation helpful? Give feedback.
-
Please see the response provided at dotnet/runtime#94269 (comment) for more context.
|
Beta Was this translation helpful? Give feedback.
-
Closing out. This is one of many duplicate proposals from the same user. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I don't know how you feel, but every time I see these things, I feel suffocated. Checking whether two objects are equal, comparing two objects, these operations are unreasonably designed as ordinary members, which requires checking for null references when calling. At the same time, the semantic overlap between the "==" operator and ordinary methods is frustrating.
Now you can use the "==" interface to replace IEqualityComparer to unify semantics, and type T can directly implement this interface. IEquatable, IEqualityComparer, and Equals(object) can all be discarded. Note that the "==" interface can still be implemented by types other than T, and you only need to pass the comparison type you want to use when using it. Comparison can also be improved in a similar way.
Beta Was this translation helpful? Give feedback.
All reactions