Introduce Explaining Variable

The Introduce Explaining Var refactoring introduces a local variable, and replaces the selected text (expression) with the variable.
The variable is initialized using the selected text. Commonly used to make complex expressions more readable.

An Example


This calculates the price of an order by subtracting a discount from the base price.

To make this code more readable we could introduce an explaining variable discount using the refactoring.
To do that, select the discount expression “(MaxInt(0, (Quantity – 500)) * ItemPrice * 0.05)” and invoke
the refactoring.

This will be the result: