All rules
IDE0019Language rules (pattern matching preferences)
Use pattern matching to avoid as followed by a null check
Use pattern matching to avoid as followed by a null check
Microsoft docsDescription
This style rule concerns the use of C# pattern matching over an as expression followed by a null check. This rule is similar to IDE0260, which flags the use of an as expression followed by a member read through the null-conditional operator.
Example
// csharp_style_pattern_matching_over_as_with_null_check = true
if (o is string s) {...}
// csharp_style_pattern_matching_over_as_with_null_check = false
var s = o as string;
if (s != null) {...}Configurable options
Vote for the value each option should take in the generated .editorconfig.
csharp_style_pattern_matching_over_as_with_null_check default:
trueYour vote
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0