Split or merge if statements
This refactoring applies to:
C#
Visual Basic
What: What: Split or merge if statements.
When: You want to split an if
statement that uses the &&
or ||
operators into a nested if
statement, or merge an if
statement with an outer if
statement.
Why: It's a matter of style preference.
If you want to split the if
statement:
Place your cursor in the
if
statement by the&&
or||
operator.Press Ctrl+. to trigger the Quick Actions and Refactorings menu.
Select Split into nested if statements.
If you want to merge the inner if
statement with the outer if
statement:
Place your cursor in the inner
if
keyword.Press Ctrl+. to trigger the Quick Actions and Refactorings menu.
Select Merge with outer if statement.