List and Array
Why use a list instead of an array?
The most straightforward version of the GetComponents method simply returns an array with all components of the requested type. This means that a new array gets created every invocation, which is each update in our case. An alternative version has a list parameter. The advantage of that one is that it will put the components in the list instead of creating a new array.
It is not a crucial optimization at all in our case, but it is a good habit to use the list variant whenever you're grabbing components often.
Array.Resize<T>(T[], Int32) Method (System)
Changes the number of elements of a one-dimensional array to the specified new size.
C#
public static void Resize<T> (ref T[]? array, int newSize);
Type Parameters
T
The type of the elements of the array.
Parameters
array T[]
The one-dimensional, zero-based array to resize, or null to create a new array with the specified size.
newSize Int32
The size of the new array.