Deep Dive on Closure Pitfalls
I’ve blogged about closures in C# and their pitfalls before. I keep seeing problems with closures–more now that lambdas expressions and statements (“lambdas”) are becoming more widespread–even with experienced developers. So, I’d thought i’d post about some of the details surrounding where the C# compiler generates closures in the hopes that people will recognize more where they write code that creates a closure and its context. The C# language spec does not refer specifically to “closures”, with regard to capturing state for anonymous methods (including lambdas)–it refers to “outer variables” and “captured outer variables”. The captured outer variables for a specific … Continue reading Deep Dive on Closure Pitfalls