Do you look for opportunities to use Linq?
12/02/2013 11:38 PM by
Linq is a fantastic addition to .Net which lets you write clear and beautiful declarative code. Linq allows you to focus more on the what and less on the how.
You should look for opportunities to replace your existing code with Linq.
For example, replace your foreach loops with Linq.
Figure: Bad Example - imperative programming using a foreach loop
var lucrativeCustomers = new List<Customer>();
foreach (var customer in Customers)
if (customer.Orders.Count > 0)
Figure: Good Example - declarative programming using Linq
var lucrativeCustomers = Customers.Where(c => c.Orders.Count > 0).ToList();
Do you feel this rule needs an update?