C# Language Arrays Comparing arrays for equality

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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


Got any C# Language Question?