There is no static Equals method in the Array class, so you are actually using Object.Equals , which determines whether these two objects refer to the same object.
If you want to check if arrays contain the same elements in the same order, you can use the SequenceEquals extension method:
childe1.SequenceEqual(grandFatherNode)
Edit:
To use SequenceEquals with multidimensional arrays, you can use the extension to list them. Here is the extension to enumerate a two-dimensional array:
public static IEnumerable<T> Flatten<T>(this T[,] items) { for (int i = 0; i < items.GetLength(0); i++) for (int j = 0; j < items.GetLength(1); j++) yield return items[i, j]; }
Using:
childe1.Flatten().SequenceEqual(grandFatherNode.Flatten())
If your array has more sizes than two, you will need an extension that supports this number of dimensions. If the number of measurements changes, you will need a slightly more complex code to cyclically change the number of measurements.
First you need to make sure that the number of dimensions and the size size of the arrays are the same before comparing the contents of the arrays.
Edit 2:
Turns out you can use the OfType<T> method to align the array, as RobertS noted. Naturally, this only works if all the elements can be cast to the same type, but this is usually the case if you can compare them. Example:
childe1.OfType<Person>().SequenceEqual(grandFatherNode.OfType<Person>())
Guffa Dec 12 2018-10-12 18:57
source share