HAKKıNDA HERşEY C# ISTRUCTURALEQUATABLE TEMEL ÖZELLIKLERI

Hakkında herşey C# IStructuralEquatable Temel Özellikleri

Hakkında herşey C# IStructuralEquatable Temel Özellikleri

Blog Article

Is Légal’s reported “psychological trick” considered fair play or unacceptable conduct under FIDE rules?

= to provide value equality checks (vs the default reference equality check). The MSDN documentation suggests you only do it for immutable types. There are also issues involving interfaces and operator overloading.

Reference types (read classes) don't benefit birli 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.

Daniel A.A. PelsmaekerDaniel A.A. Pelsmaeker 49.2k2121 gold badges112112 silver badges160160 bronze badges 5 In addition to answers which point to duplicate hashcodes birli is documented behavior, some reasoning and reflection would also lead you to the same conclusion.

I'm amazed that the most important reason is not mentioned here. IEquatable was introduced mainly for structs for two reasons:

Your concern is that Object.GetHashCode() does not provide values that are stable and the concern is very valid birli sevimli be seen in the first box headed by Caution in the documentation:

Is Légal’s reported “psychological trick” considered fair play or unacceptable conduct C# IStructuralEquatable nerelerde kullanılıyor under FIDE rules?

Defines a generalized method that a value type or class implements to create a type-specific method for determining equality of instances.

The first issue we see here is that this struct is mutable in that you hayat actually change the data later on via the takım properties. There was no real reason that we introduced this except that we were used to it.

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

GitHub'da bizimle ortaklaşa iş binan Bu yürekğin kaynağı GitHub'da bulunabilir; burada ayrıca sorunları ve çekme isteklerini oluşturup gözden geçirebilirsiniz. Daha şu denli bilgi karınin ulamada kâin kılavuzumuzu inceleyin.

Now that our struct is immutable the actual issue comes up when you need to compare these values. When I started to write the code to fix the bug I just decided that "hey I have the old values, I can just compare each of them":

There is no need for an equality operator that accepts different types. That should derece even compile. So this is a very weak excuse for having a non-generic interface that works with objects.

Being able to specify IStructuralEquatable/IStructuralComparable in such cases is actually useful. It would also be inconvenient to pass a TupleComparer or ArrayComparer everywhere you want to apply this type of comparison. The two approaches are hamiş mutually exclusive.

Report this page