FC37: ParamsArray<T>

A struct to avoid/reduce allocation for params array

There are a quite few APIs in .NET which support variable number of arguments. There is small issue in the implementation, an array is allocated to hold the arguments, even for zero arguments.

In .Net Framework 4.8, an internal struct ParamsArray is added for a few string related methods to avoid such allocations. This could be a useful pattern for our future posts, so let’s borrow it, but change to generic version:

Sample usage:

Array allocation is avoided for up to 3 arguments.