O'Reilly logo

Microsoft Visual Studio 2015 Unleashed, Third Edition by Mike Snell, Lars Powers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Introduce Local

The Introduce local refactor allows you to convert an expression of code to a local variable within your method (or similar). This can make your code easier to read. It is also useful if you plan to reuse the result of the expression multiple times. Figure 9.12 shows converting the discount amount (total * .10) to a local variable.

Image

FIGURE 9.12 Use Introduce Local to move code expressions into local variables.

The result of the Refactor operation is a variable to represent the discount. You can now change the code to make it more readable, as follows.

//apply discount ruleif (total > discountThreshold) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required