From how I understand this, Resharper will throw an error if you access a variable from a delegate (closure), and then modify the variable before you execute the delegate. This mostly happens if you access a for loop variable inside a delegate/lambda and execute it outside the loop. If your code is like:
foreach (filter in filters)
{
if (filter != null) {
if (filter.CityId != 0) {
ads = ads.Where(x => x.Ad.CityId == filter.CityId);
}
if (filter.BusinesCategoryId != 0) {
ads = ads.Where(x => x.BusinessCategoryId == filter.BusinesCategoryId);
}
}
}
return ads.ToList()
Then it will not behave like you'd expect it to. But if you execute the lambda expressions inside the loop scope then you would have no problem.
I wont explain why it behaves that way because a lot of people already explained it very well:
UPDATE:
To answer "Why do local variable?" is because the fix to the above problem is using a local variable (i.e., inside the loop) and using that in your lambda. That way you are closing over the different instances of the variable for each instance of the lambda.