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:

MMX
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.