How to compare arrays in C#?

mahdi  picture mahdi · Dec 12, 2010 · Viewed 137.1k times · Source

Possible Duplicate:
Easiest way to compare arrays in C#

How can I compare two arrays in C#?

I use the following code, but its result is false. I was expecting it to be true.

Array.Equals(childe1,grandFatherNode);

Answer

AMing picture AMing · Feb 10, 2012

You can use the Enumerable.SequenceEqual() in the System.Linq to compare the contents in the array

bool isEqual = Enumerable.SequenceEqual(target1, target2);