ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: Merge conditional ?: expression into conditional access

Last modified: 08 April 2024

Starting from C# 6.0, you can use the null-conditional operator (?.) to test for null before performing member access.

If you use the conditional ?: (ternary) operator for nullability check when accessing symbol's members, ReSharper suggests replacing it with a more elegant ?. operator.

Here is an example of a quick-fix suggested by this inspection: