LINQ Interview Question #130
What is SequenceEqual in LINQ?
Advanced LINQ, Practical Problems & Senior Interview Scenarios Senior Advanced
Quick Interview Answer
SequenceEqual determines whether two sequences contain equal elements in the same order and have the same length. Equality is evaluated using the applicable equality comparer.
Detailed Explanation
SequenceEqual determines whether two sequences contain equal elements in the same order and have the same length. Equality is evaluated using the applicable equality comparer.
It differs from set comparison because order and duplicate occurrences matter.
Code Example
var a = new[] { 1, 2, 3 };
var b = new[] { 1, 2, 3 };
var c = new[] { 3, 2, 1 };
bool same = a.SequenceEqual(b); // true
bool reordered = a.SequenceEqual(c); // false