Thomas Levesque 12/7/2014

Optimize ToArray and ToList by providing the number of elements

Read Original

The article details the inefficiency of C#'s ToArray and ToList methods when the element count is unknown, as with LINQ queries. It explains the internal resizing/copying behavior and proposes a custom extension method, ToArray(int count), that accepts a known count to pre-allocate the correct array size, improving performance.

Optimize ToArray and ToList by providing the number of elements

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week