RCS1146: Use conditional access
Properties
Property | Value |
---|---|
Default Severity | Info |
Minimum language version | 6.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();