Skip to content

Latest commit

 

History

History
23 lines (14 loc) · 569 Bytes

File metadata and controls

23 lines (14 loc) · 569 Bytes

Pattern: Zero-length array allocation

Issue: -

Description

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>();

Further Reading