Split or merge if statements

Applies to: yesVisual Studio noVisual Studio for Mac noVisual Studio Code

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.

How-to

If you want to split the if statement:

  1. Place your cursor in the if statement by the && or || operator.

  2. Press Ctrl+. to trigger the Quick Actions and Refactorings menu.

    Split If Statement

  3. Select Split into nested if statements.

    Split If Statement Complete

If you want to merge the inner if statement with the outer if statement:

  1. Place your cursor in the inner if keyword.

  2. Press Ctrl+. to trigger the Quick Actions and Refactorings menu.

    Merge If Statement

  3. Select Merge with outer if statement.

    Merge If Statement Complete

See also