Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IStructuralEquatable vs Equals?

Tags:

according to msdn

IStructuralEquatable

Defines methods to support the comparison of objects for structural equality. Structural equality means that two objects are equal because they have equal values. It differs from reference equality, which indicates that two object references are equal because they reference the same physical object.

isnt it what Equals should do ? ( when overriding IEquatable) ?

like image 275
Royi Namir Avatar asked Mar 03 '12 17:03

Royi Namir


1 Answers

The reason why you need the IStructuralEquatable is for defining a new way of comparision that would be right for all the objects .

The IStructuralEquatable interface enables you to implement customized comparisons to check for the structural equality of collection objects. That is, you can create your own definition of structural equality and specify that this definition be used with a collection type that accepts the IStructuralEquatable interface.

For example if you want a list that will sort all its elements by a specific definition. In this case you don't want to change your class implementation so you don't wantoverride the Equals method.

this will define a general way to compare objects in your application.

like image 126
user844541 Avatar answered Dec 01 '22 00:12

user844541