Easiest way to compare arrays in C#

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *