Skip to content

Allow params to use collections C# 13.0code reductionperformance

The params keyword no longer has to use an array but can use other collection types.

The params modifier keyword could only take the supplied arguments and put them into an array.

With C# 13 the params keyword can now be used with other collection types such as List<T>, Span<T>, IEnumerable<T> etc.

Code

C#
var results = SquareList(1, 2, 3, 4, 5);
// ...
public List<int> SquareList(params List<int> numbers)
  => list.ConvertAll(x => y * y);
C#
var results = SquareList(1, 2, 3, 4, 5);
// ...
public List<int> SquareList(params int[] numbers)
  => new List<int>(numbers).ConvertAll(x => y * y);

Notes

  • If you specify an interface type, the compiler will choose an appropriate collection type to use.

More information