Skip to main content

Simplify Expression

  • 2 minutes to read

Purpose

Used to simplify a boolean expression or bitwise operation if it is possible. The simplification involves removing unnecessary parentheses, toggling negations, parameter reordering, etc. without affecting the expression’s return value but making the entire expression easier to read.

Availability

Available in the following cases:

  • When the caret is on an if statement whose condition can be simplified.
  • When the caret is on an assignment or return statement which has a Boolean expression (bitwise operation) that can be simplified.
  • When a Boolean expression (bitwise operation) that can be simplified is selected.

Usage

  1. Place the caret on an if statement whose condition can be simplified.

    Note

    The blinking cursor shows the caret’s position at which the Refactoring is available.

    if (a || b && a || c)
        return;
    
  2. Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
  3. Select Simplify Expression from the menu.

After execution, the Refactoring replaces the condition with a simpler equivalent.

if (a || c)
    return;

Note

This Refactoring uses the Quine–McCluskey algorithm for simplification.

See Also