All rules
IDE0150Language rules (expression-level preferences)
Prefer null check over type check
Prefer null check over type check
Microsoft docsDescription
This style rule flags use of the is {type} statement when is not null can be used instead. Similarly, it flags use of the is not {type} statement in favor of is null. Using is null or is not null improves code readability.
Example
// Violates IDE0150.
if (numbers is not IEnumerable<int>) ...
// Fixed code.
if (numbers is null) ...Configurable options
Vote for the value each option should take in the generated .editorconfig.
csharp_style_prefer_null_check_over_type_check default:
trueYour vote
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0