50
What exactly is the Outer Variable Trap? Explanation and examples in C# are appreciated.
EDIT: Incorporating Jon Skeet's diktat :)
What exactly is the Outer Variable Trap? Explanation and examples in C# are appreciated.
EDIT: Incorporating Jon Skeet's diktat :)
Something like
foreach (var s in strings)
var x = results.Where(r => (r.Text).Contains(s));
Will not give the results you're expecting because the Contains is not executed for each iteration. Assigning s to a temporary variable inside the loop will fix this, though.