How to compare multidimensional arrays in C# ?
A multidimensional array can be used in linq as one dimensional enumerable. You just need to check also for the length of all dimensions. This snippet should be enough:
var equal =
data1.Rank == data2.Rank &&
Enumerable.Range(0,data1.Rank).All(dimension => data1.GetLength(dimension) == data2.GetLength(dimension)) &&
data1.Cast<double>().SequenceEqual(data2.Cast<double>());
You can flat a multi-dimension array with .Cast<String>
Console.WriteLine("2D Array");
String[,] array2d = new String[,] { { "A1", "B1" }, { "A2", "B2" } };
foreach(var s in array2d.Cast<String>())
Console.Write(s + ", ");
Console.WriteLine("\r\n3D Array");
String[,] array3d = new String[,] { { "A1", "B1", "C1" }, { "A2", "B2", "C1" } };
foreach (var s in array3d.Cast<String>())
Console.Write(s + ", ");
Output
2D Array
A1, B1, A2, B2,
3D Array
A1, B1, C1, A2, B2, C1,