JetBrains Rider
 
2024.3
Get JetBrains Rider

Code inspection: 'if-return' statement can be rewritten as 'return' statement

Last modified: 08 April 2024

The conditional ?: (ternary) operator in C# is the most elegant way to execute one of two simple expressions depending on the value of a simple boolean expression.

Therefore, if JetBrains Rider encounters an if statement that returns control, immediately followed by another return, it suggests replacing those with a single return that makes use of the ?: operator.

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