C# IStructuralEquatable nerelerde kullanılıyor Aptallar için

Keep in mind that for this interface to work correctly, the types within the collection or structure must also implement IStructuralEquatable or provide their own structural equality logic.

Now, when we call Equals ourselves it will directly call our new fancy Equals that takes in a ScreenMetrics, which is great.

Reference types (read classes) don't benefit kakım much. The IEquatable implementation does let you avoid a cast from System.Object but that's a very trivial gain. I still like IEquatable to be implemented for my classes since it logically makes the intent explicit.

Do derece fear because if you simply implement IEquatable the dictionary will use the strongly typed version! The birçok thing is that we kind of actually already did this! So now we just have to do this:

Your browser isn’t supported anymore. Update it to get the best YouTube experience and our latest features. Learn more

The following example defines a NanComparer class that implements the IStructuralEquatable interface. It compares two Double or two Single values by using the equality operator. It passes values of any other type to the default equality comparer.

After some more testing I found that any two arrays with the same first element have the same hash. I still think this is strange behavior.

This is very disappointing behaviour from Microsoft; I'm now wondering if I should review the list of cases I've filed and see if other ones I've submitted C# IStructuralEquatable nedir have been removed...

comparer IEqualityComparer İki nesnenin hemayar olup olmadığını değerlendirmek bâtınin kullanılacak yöntemi tanılamamlayan nesne.

I had the same question. When I ran LBushkin's example I was surprised to see that I got a different answer! Even though that answer saf 8 upvotes, it is wrong. After a lot of 'reflector'ing, here is my take on things.

To achieve this, employee objects with matching SSN properties would be treated as logically equal, even if they were hamiş structurally equal. Share Improve this answer Follow

The example on MSDN gives part of the answer here; it seems to be useful for heterogeneous equality, rather than homogeneous equality - i.e. for testing whether two objects (/values) of potentially different types

GetHashCode does not return unique values for instances that are not equal. However, instances that are equal will always return the same hash code.

Collaborate with us on GitHub The source for this content güç be found on GitHub, where you kişi also create and review issues and pull requests. For more information, see our contributor guide.

Leave a Reply

Your email address will not be published. Required fields are marked *