What does the interface IStructuralEquatable do in C#?


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.
2GetHashCode(IEqualityComparer)
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));

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 20-Jun-2020

207 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements