Skip to main content

RCS1146: Use conditional access

Properties

PropertyValue
Default SeverityInfo
Minimum language version6.0

Examples

Example #1

diagnostic.cs
if (s != null && s.StartsWith("a"))
{
}
fix.cs
if (s?.StartsWith("a") == true)
{
}

Example #2

diagnostic.cs
if (dic != null && dic[0].StartsWith("a"))
{
}
fix.cs
if (dic?[0].StartsWith("a") == true)
{
}

Example #3

diagnostic.cs
if (x != null)
x.Foo();
fix.cs
x?.Foo();

Applies to