Skip to main content
Source: AL0034UseWhereNotNullAnalyzer.cs

Description

Filtering null values with Where(x => x != null) is a common pattern that can be simplified using the WhereNotNull() extension.

Bad Code

Good Code

Properties

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

Configuration

Notes

  • Also changes the return type from IEnumerable<T?> to IEnumerable<T>
  • Eliminates nullable warnings in subsequent code
  • Clearer intent than explicit null check