C# IStructuralEquatable nedir Için Adım Haritaya göre Yeni Adım

Wiki Article

Why do we have IStructuralComparable and IStructuralEquatable when there already exist the IComparable and IEquatable interfaces? The answer I would offer is that, in general, it's desirable to differentiate between reference comparisons and structural comparisons.

Important Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

It differs from reference equality, which indicates that two object references are equal because they reference the same physical object.

LBushkinLBushkin 131k3333 gold badges217217 silver badges265265 bronze badges 11 8 Why birey't you just specify an IEqualityComparer yourself that does this? What does the IStructuralEquatable interface add to this?

Birli an example, it might make sense for two different instances of an Employee class to be considered equal if they both represent the same entity in your system.

I never put much thought into using a struct over a class or even additional optimizations because to me the struct was optimized already. When I was working on fixing a bug in our DeviceDisplay to hamiş trigger new events unless a value changed a whole new world opened up to me.

The IEquatable implementation will require one less cast for these classes and bey a result will be slightly faster than the standard object.Equals method that would be used otherwise. Bey an example see the different implementation of the two methods:

In my implementation I delegated the task of calculating hash codes to the internal array. While testing it, to my great surprise, I found that my two different arrays had the same structural hash code

The first issue we see here is that this struct is mutable in that you gönül actually change the data later on via the set 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 kişi also create and review issues and pull requests. For more information, see our contributor guide.

Fakat, fruits1 ve fruits3 dizileri aynı elemanlara farklı sıralarda malik başüstüneğundan, CompareTo metodu farklı bir mesabe döndürür ve bu dizilerin konstrüktif olarak hemayar olmadığını belirtir.

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

The IStructuralEquatable interface supports only custom comparisons for structural equality. The IStructuralComparable interface supports custom structural comparisons for sorting and ordering.

Being able to specify IStructuralEquatable/IStructuralComparable C# IStructuralEquatable Nasıl kullanılır 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 wiki page