Local Functions vs Lambda Expressions in C#
Local functions and lambda expressions in C# serve different purposes and have distinct performance characteristics. Local functions are methods nested within other methods and excel in performance since they can avoid heap allocation and use struct instead of class captures. Lambda expressions, while concise and useful for passing as delegates, generally require heap allocation and object instantiation. Local functions can be generic, recursive, and used as iterators, whereas lambda expressions struggle with these features. Thus, local functions are often more versatile and performant, especially when not using APIs that demand delegates.