All rules
IDE0039Language rules (expression-level preferences)

Use local function instead of lambda

Use local function instead of lambda

Microsoft docs

Description

This style rule concerns the use of local functions versus lambda expressions (anonymous functions).

Example

// csharp_style_prefer_local_over_anonymous_function = true
int fibonacci(int n)
{
    return n <= 1 ? 1 : fibonacci(n-1) + fibonacci(n-2);
}

// csharp_style_prefer_local_over_anonymous_function = false
Func<int, int> fibonacci = (int n) =>
{
    return n <= 1 ? 1 : fibonacci(n - 1) + fibonacci(n - 2);
};

Configurable options

Vote for the value each option should take in the generated .editorconfig.

csharp_style_prefer_local_over_anonymous_function
default: true
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0