Pattern: Zero-length array allocation
Issue: -
Initializing a zero-length array leads to an unnecessary memory allocation. Instead, use the statically allocated empty array instance by calling the Array.Empty
method. The memory allocation is shared across all invocations of this method.
Example of incorrect code:
var a = new int[0];
Example of correct code:
var a = System.Array.Empty<int>();