Skip to main content

RCS1206: Use conditional access instead of conditional expression

Properties

PropertyValue
Default SeverityInfo
Minimum language version6.0

Examples

Example #1

diagnostic.cs
var x = new Foo();

// ...

string s = (x != null) ? x.ToString() : null;
fix.cs
string s = x?.ToString();

Example #2

diagnostic.cs
int? x = null;

// ...

int i = (x != null) ? x.Value.GetHashCode() : 0;
fix.cs
int i = x?.GetHashCode() ?? 0;

Applies to