tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

New IStructuralEquatable, IStructuralComparable and StructuralComparisons

4 Jul 2009 .NET, C#, F#

.NET Framework 4 comes with (among others) with two new interfaces. IStructuralEquatable and IStructuralComparable. These are implemented (right now in Beta 1) by Array and Tuple(s).

With this new implementations and StructuralComparisons you can check arrays and tuples for structural equality (or compare these).

object[] o1 = new object[] { 1, "2" };
object[] o2 = new object[] { 1, "2" };
Console.WriteLine(o1.Equals(o2));
Console.WriteLine(o1.Equals(o2, StructuralComparisons.StructuralEqualityComparer));

The code above writes first false and then true. The first one is classic “old-school” Equals. Following line is using new structural comparison, thus the true as result. Neat, isn’t it?

By the way, F# is now using these interfaces too.