Chapter 7, LINQ Performance
- Use the index rather than the
Last()call for direct access to the last element in a collection. Avoid using theletkeyword 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
letkeyword 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
letkeyword. - Closures with parameters perform better than closures without parameters.