All rules
IDE0031Null-checking preferences MS default: Suggestion

Use null propagation

Prefer the null-conditional operator `?.` over null-check conditionals.

Microsoft docs

Description

Suggests replacing x != null ? x.Y : null with x?.Y.

Why it matters

Null propagation is concise and avoids accidentally dereferencing a null value.

Examples

Avoid
var length = text != null ? text.Length : (int?)null;
Prefer
var length = text?.Length;

Configurable options

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

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