Skip to content

Returning Empty Arrays Efficiently

Rather than creating a new empty array or enumerable, which will allocate space on the heap every time and can easily add up to a GC clean-up over time, simply return one of the following:

return Array.Empty<T>();

or

return Enumerable.Empty<T>();

This memory is only ever allocated once during the application's lifetime.