Lambda Expressions · TL;DR
1 min readTL;DR
A lambda expression (x => x 2) is an anonymous function written inline. On its own it has no type: the compiler converts it either to a delegate (compiled IL you can call, such as Func<int, int>) or to an expression tree (Expression<Func<int, int>>, a data structure describing the code, which LINQ providers like EF Core translate to SQL). Since C# 10 a lambda can also have a "natural type", so var f = (int x) => x 2; works. At the memory level, a lambda that captures nothing is compiled to a method whose delegate is created once and cached; a lambda that captures outer variables becomes a closure (a heap object plus a delegate per creation). The traps interviewers probe: async lambdas turning into async void, Func<> vs Expression<Func<>> deciding whether a query runs in SQL or in memory, captured variables in loops, and hidden allocations on hot paths.