Extracting a Single Line of Code

Sometimes you want to extract a single line of code or a portion of a line of code as its own method. For example, you might have a calculation that is done as part of a line of code but is common enough to warrant its own method. Alternatively, you might need to extract an object assignment to add additional logic to it. In either case, the code editor supports this type of extraction.

Let’s look at an example. Suppose you have the following line of code that calculates an invoice’s total inside a loop through the invoice items list.

total += item.Price * item.Quantity;

You might want to extract just the portion of the assignment that calculates a line item’s total (price * quantity). ...

Get Microsoft Visual Studio 2015 Unleashed, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.