Easiest way to compare arrays in C#

asmo picture asmo · Jul 13, 2010 · Viewed 207k times · Source

In Java, Arrays.equals() allows to easily compare the content of two basic arrays (overloads are available for all the basic types).

Is there such a thing in C#? Is there any "magic" way of comparing the content of two arrays in C#?

Answer

Quartermeister picture Quartermeister · Jul 13, 2010

You could use Enumerable.SequenceEqual. This works for any IEnumerable<T>, not just arrays.