Description
Filtering null values withWhere(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?>toIEnumerable<T> - Eliminates nullable warnings in subsequent code
- Clearer intent than explicit null check
