Monday, October 30, 2017

C# 7: Lambdas vs Local functions

C# 7 introduces the concept of local functions. Local functions can be nested in other functions similar to anonymous delegates or lambda expressions. Doesn’t this make local functions redundant? Not at all, anonymous functions and lambda expressions have certain restrictions that local functions have not.

Here is a list of things a local function can do that lambda’s can’t:

  • Local functions can be called without converting them to a delegate

  • Local functions can be recursive

  • Local functions can be iterators

  • Local functions can be generic

  • Local functions have strictly more precise definite assignment rules

  • In certain cases, local functions do not need to allocate memory on the heap

More information can be found at:

No comments: