Structural Mappings for Arrays

In F #:

[0] = [0] = true 

In C # or .NET BCL in general:

 StructuralComparisons.Equals(new int[] { 0 }, new int[] { 0 }) == false 

Why?


P.S:

The reason I thought I had the “right” Equals is because it turned out to be true:

 var a = new { X = 3, Y = new { Z = -1 } }; var b = new { X = 3, Y = new { Z = -1 } }; StructuralComparisons.Equals(a, b) == true; 
+5
source share
1 answer

This is because you are going to object.Equals(objA, objB) , which cannot handle such a comparison.

Instead, do the following:

 StructuralComparisons.StructuralEqualityComparer.Equals(..., ...) 
+8
source

All Articles