null-coalescing
operator to simplify the null
check CS-R1024null
check expression can be simplified 53
54 // CS-R1024: Use `null-coalescing` operator, i.e. rewrite as `i ?? 1`.
55 // https://deepsource.io/directory/analyzers/csharp/issues/CS-R1024
56 var value = i != null ? i : 1; 57
58 // CS-R1007: Use `Guid.Empty` instead.
59 // https://deepsource.io/directory/analyzers/csharp/issues/CS-R1007
ternary
conditional operator evaluates the specified boolean expression and returns the result of one of the two expressions specified. However, when dealing with null
, i.e. null
checks, the null-coalescing
operator can be used instead to simplify the entire expression.
return foo != null ? foo : bar;
return foo ?? bar;