Why does ReSharper tell me “implicitly captured closure”?

The warning tells you that the variables end and start stay alive as any of the lambdas inside this method stay alive. Take a look at the short example protected override void OnLoad(EventArgs e) { base.OnLoad(e); int i = 0; Random g = new Random(); this.button1.Click += (sender, args) => this.label1.Text = i++.ToString(); this.button2.Click += … Read more

LINQ: Not Any vs All Don’t

Implementation of All according to ILSpy (as in I actually went and looked, rather than the “well, that method works a bit like …” I might do if we were discussing the theory rather than the impact). public static bool All<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate) { if (source == null) { throw Error.ArgumentNull(“source”); } … Read more

Invert “if” statement to reduce nesting

It is not only aesthetic, but it also reduces the maximum nesting level inside the method. This is generally regarded as a plus because it makes methods easier to understand (and indeed, many static analysis tools provide a measure of this as one of the indicators of code quality). On the other hand, it also … Read more

Access to Modified Closure

In this case, it’s okay, since you are actually executing the delegate within the loop. If you were saving the delegate and using it later, however, you’d find that all of the delegates would throw exceptions when trying to access files[i] – they’re capturing the variable i rather than its value at the time of … Read more