RCS1206: Use conditional access instead of conditional expression
Properties
Property | Value |
---|---|
Default Severity | Info |
Minimum language version | 6.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;