There is a special method called SequenceEqual :
IList<int> myList1 = new List<int>(...); IList<int> myList2 = new List<int>(...); if (myList1.SequenceEqual(list2)) { ... }
You can perform selective sequence comparisons using the Zip method. For example, to see if there is any pair in the difference of three, you can do this:
IList<int> myList1 = new List<int>(...); IList<int> myList2 = new List<int>(...); if (myList1.Zip(list2, (a, b) => Math.Abs(a - b)).Any(diff => diff > 3)) { ... }
source share