Chapter 7, LINQ Performance
- Use the index rather than the
Last()
call for direct access to the last element in a collection. Avoid using thelet
keyword in your LINQ queries. Convert a list to an array to perform group by, and then return an enumerator. - The compiler generates more lines of code that take longer to run, and more memory is allocated at runtime than when the
let
keyword is not used. - Filter items starting with objects that have the least number of items, followed by the objects with an increasing number of items. Also, avoid using the
let
keyword. - Closures with parameters perform better than closures without parameters.