Fork me on GitHub
TypeName ExistenceOperatorAnalyzer
Check Id CC0018
Category Style
Severity Info

Cause

The null-propagating operator allow for terse code to handle potentially null variables.

Example

namespace ConsoleApplication1
{
    class TypeName
    {
        public string Foo()
        {
            A a = null;
            if (a != null)
                return a.Name;
            else
                return null;
        }
    }
}

Code fix

A code fix will be presented to you that will transform the code:

namespace ConsoleApplication1
{
    class TypeName
    {
        public string Foo()
        {
            A a = null;
            return a?.Name;
        }
    }
}

Code fix

Related rules

None

See also

TBD