JetBrains Rider 2024.1 Help

Code Inspection: Redundant 'else' keyword

Category

Redundancies in Code

ID

RedundantIfElseBlock

EditorConfig

resharper_redundant_if_else_block_highlighting

Default severity

Hint

Language

C#

Requires SWA

No

Certain if-else conditions can have their else clause removed without changing the semantic. Consider the following method:

public int Sign(double d) { if (d > 0.0) return 1; else return -1; }

In the above, the else statement can be safely removed because its if clause returns from the method. Thus, even without the else, there’s no way you’ll be able to proceed past the if clause body.

Last modified: 17 April 2024