All rules
IDE0046Language rules (expression-level preferences)
Use conditional expression for return
Use conditional expression for return
Microsoft docsDescription
This style rule concerns the use of a ternary conditional expression versus an if-else statement for return statements that require conditional logic.
Example
// dotnet_style_prefer_conditional_expression_over_return = true
return expr ? "hello" : "world"
// dotnet_style_prefer_conditional_expression_over_return = false
if (expr)
{
return "hello";
}
else
{
return "world";
}Configurable options
Vote for the value each option should take in the generated .editorconfig.
dotnet_style_prefer_conditional_expression_over_return default:
trueYour vote
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0