Aller au contenu

Array empty (ARCH603)

Ce contenu n’est pas encore disponible dans votre langue.

Key dotnet.performance.array-empty · Severity warning · Category performance

Creating a new empty array allocates each time; Array.Empty<T>() returns a single cached instance.

public int[] GetIds() => new int[0];
public int[] GetIds() => Array.Empty<int>();

Use Array.Empty<T>() for empty arrays.