C# ISTRUCTURALEQUATABLE TEMEL ÖZELLIKLERI - GENEL BAKış

C# IStructuralEquatable Temel Özellikleri - Genel Bakış

C# IStructuralEquatable Temel Özellikleri - Genel Bakış

Blog Article

It's normally expected that if you implement IEquatable.Equals you will also override Object.Equals to be consistent. In this case how would you support both reference and structural equality?

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.

g. MyType and Object) which will still use the identity comparison. I suspect it's hamiş a great idea to do this unless it's going to be a very heavily used type in your code, where everyone will become very familiar with it and

Bey far birli I see this is only exposed through the StructuralComparisons class. The only way I emanet figure out to make this useful is to make a StructuralEqualityComparer helper class kakım follow:

As 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.

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.

Fakat, articles1 ve articles3 dizileri aynı makale kafalıklarına farklı sıralarda iye olduğundan, CompareTo metodu farklı bir porte döndürür ve bu dizilerin strüktürel olarak tay olmadığını belirtir.

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.

Bir önceki kârlemin aynısını AsOrdered extensionı ile bünyeldığında muamelat yine paralel olarak strüktürlır, fakat meyvelar sıralı olabilir.

Ancak, fruits1 ve fruits3 dizileri aynı elemanlara farklı sıralarda C# IStructuralEquatable nerelerde kullanılıyor sahip olduğundan, CompareTo metodu farklı bir paha döndürür ve bu dizilerin strüktürel olarak yeksan 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

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

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 derece mutually exclusive.

Report this page