C# & CLR Internals (50 Qs)•Part 3: CLR Internals, Native AOT & Production Diagnostics (25 - 35)
How does the C# Compiler lower Lambda Expressions and Closures into compiler-generated display classes?
senior LevelMost AskedClosures & Scope
In Simple Words: When a lambda captures an outer local variable (a closure), the Roslyn compiler synthesizes an internal class (display class), promotes the local variable to a heap field on that class, and turns the lambda into an instance method of that class.