Convert the loop in Customer.Statement to a Linq Aggregate method
authorMichael Welch <michaelgwelch@gmail.com>
Thu, 9 Feb 2012 02:31:12 +0000 (20:31 -0600)
committerMichael Welch <michaelgwelch@gmail.com>
Thu, 9 Feb 2012 02:31:12 +0000 (20:31 -0600)
.gitignore
RefactoringChapter1/Customer.cs

index fa8a8a1..898c86c 100644 (file)
@@ -1,2 +1,3 @@
 bin/
+*.pidb
 *.userprefs
index 93cab22..31228c8 100644 (file)
@@ -29,14 +29,9 @@ namespace RefactoringChapter1
                        string result = "Rental Record for " + Name + "\n";
                        
                        // determine ammounts for each line
-                       foreach (Rental rental in rentals)
-                       {
-                               
-                               // show figures for this rental
-                               result += "\t" + rental.Movie.Title + "\t" +
-                                       rental.Charge + "\n";
-                               
-                       }
+                       result += rentals.Aggregate("", (lines, rental) => lines + 
+                                                     "\t" + rental.Movie.Title +
+                                                     "\t" + rental.Charge + "\n");
                        
                        // add footer lines
                        result += "Amount owed is " + TotalCharge + "\n";