C# logoC#/
CS-R1136

Use conditional access operator or pattern matching to safely access nullable valueCS-R1136

Major severityMajor
Anti-pattern categoryAnti-pattern

While it is common to explicitly check an object's nullability before accessing its value, you can further simplify this expression by either using the conditional access operator ? or pattern matching instead. These proposed solutions are succinct and reduce your keystrokes.

Bad Practice

if (analyzer != null && analyzer.name == "csharp")
{
    // ...
}
// Using the conditional access operator
if (analyzer?.name == "csharp")
{
    // ...
}

// Using pattern matching
if (analyzer is {name: "csharp"})
{
    // ...
}