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). ...