Saturday, November 26, 2016

LINQ Performance pitfall instead a Pit stop!

I would rather named the title as Linq performance pit stop. Anyway in the interest of time, here is, one of the good examples of how we can start with something very trivial linq query to something convoluted one. Always remember the query in memory or on fly comes with its own pros and cons. One must understand how to use them and when. I took this particular example from pluralsight and thought it to be worth sharing.


by Mark Heath.

var longest=books.First(b => b.Pages==books.Max(a => a.Pages));

var mostBooks= books.Max(a => a.Pages);
var longest=books.First(b => b.Pages == mostBooks);

var longest= books.MaxBy(p => p.Pages);

Hope this useful.