Skip to main content
Source: AL0025PreferStaticLambdaAnalyzer.cs

Description

Lambda expressions and anonymous methods that don’t capture variables should be marked ‘static’ to avoid unnecessary allocations and improve performance.

Bad Code

list.Where(x => x > 0) // when no captures

Good Code

list.Where(static x => x > 0)

Properties

  • Category: Usage
  • Severity: Info
  • Enabled by default: True
  • Code fix available: True

Configuration

dotnet_diagnostic.AL0025.severity = warning