C#

C#

By DeepSource

Consider collapsing the null check CS-R1040

Anti-pattern
Autofix

The ?. operator allows you to access a property or a member only if it is non-null. Consider simplifying the highlighted expression, i.e. the object and its member's null checks via the usage of this ?. operator.

Examples

Bad Practice

if (foo == null || foo.bar == null)
{
    // ...
}

Recommended

if (foo?.bar == null)
{
    // ...
}

Reference