C# / .NET Bug Hunt Medium +20 XP
LINQ Deferred Execution
The query result changes unexpectedly after modification.
C# / .NETFind the bug
1
var query = numbers.Where(n => n > 5);2
numbers.Add(10);3
var count = query.Count(); The bug is on line 1
Select the correct fix
Show answer and explanation
Answer: Materialize with .ToList() before modifying
LINQ queries use deferred execution — they re-run on each enumeration. Call .ToList() to capture a snapshot before modifying the source.
Hint: LINQ is lazy — it re-evaluates each time.
What this challenge tests
Bug Hunt in C# / .NET: linq, deferred-execution.