Essential C# Arrays  Suggest an edit

Comparing arrays for equality

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

Table Of Contents
20 Arrays
22 Enum
25 GUID
107 Stream
108 Timers
  ↑ ↓ to navigate     ↵ to select     Esc to close