Skip to content

IStructuralEquatable.Equals on array throws for multidimensional arrays #66472

@roji

Description

@roji

Description

Array implements IStructuralEquatable, but its Equals implementation throws if a multi-dimensional array is passed.

Reproduction Steps

var arr1 = new int[2,2]; var arr2 = new int[2,2]; Console.WriteLine(typeof(IStructuralEquatable).IsAssignableFrom(arr1.GetType())); // True Console.WriteLine(StructuralComparisons.StructuralEqualityComparer.Equals(arr1, arr2)); // throws

Expected behavior

The method is expected to return true or false.

Actual behavior

Exception:

Unhandled exception. System.ArgumentException: Array was not a one-dimensional array. at System.Array.GetValue(Int32 index) at System.Array.System.Collections.IStructuralEquatable.Equals(Object other, IEqualityComparer comparer) at System.Collections.StructuralEqualityComparer.Equals(Object x, Object y) at Program.<Main>$(String[] args) in /home/roji/projects/test/Program.cs:line 20 

Regression?

No response

Known Workarounds

One can avoid using IStructuralEquatable or StructuralComparisons.StructuralEqualityComparer specifically for multidimensional arrays.

Configuration

.NET 6, Ubuntu impish, x64.

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions