Comparing arrays for equality

suggest change

LINQ provides a built-in function for checking the equality of two IEnumerables, and that function can be used on arrays.

The SequenceEqual function will return true if the arrays have the same length and the values in corresponding indices are equal, and false otherwise.

int[] arr1 = { 3, 5, 7 };
int[] arr2 = { 3, 5, 7 };
bool result = arr1.SequenceEqual(arr2);
Console.WriteLine("Arrays equal? {0}", result);

This will print:

Arrays equal? True

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents