What does the interface IStructuralEquatable do in C#?

CsharpProgrammingServer Side Programming

The IStructuralEquatable interface defines methods to support the comparison of objects for structural equality, which means that two objects are equal because they have equal values.

It includes the following two methods −

Sr.NoMethod & Description
1Equals(Object, IEqualityComparer)
The method determined whether an object is structurally equal to the current instance.
The methods a hash code for the current instance.

Let us see an example in which I have created Tuple objects and worked with IstructuralEquatable interface:

Create Tuples −

var tupleOne = Tuple.Create(26.3, Double.NaN, 35.6);
var tupleOne = Tuple.Create(26.3, Double.NaN, 35.6);

Now check the equality by calling IStructuralEquatable.Equals using default comparer.

IStructuralEquatable chk = tupleOne;
Console.WriteLine(chk.Equals(tupleTwo, EqualityComparer<object>.Default));
Updated on 20-Jun-2020 16:03:02