Code inspection: Redundant capacity argument
This inspection reports a capacity argument whose value is smaller than the number of elements already provided for a List<T>. In this case, the list will have to grow while the initializer or collection expression is evaluated, so the specified initial capacity is not useful.
The inspection applies to new List<T>(capacity) { ... } initializers and to C# collection expressions that use with(capacity: ...).
Example
using System.Collections.Generic;
var numbers = new List<int>(capacity: 2) { 1, 2, 3 };
using System.Collections.Generic;
var numbers = new List<int>(capacity: 3) { 1, 2, 3 };
Collection expression example
using System.Collections.Generic;
List<int> numbers = [with(capacity: 2), 1, 2, 3];
using System.Collections.Generic;
List<int> numbers = [with(capacity: 3), 1, 2, 3];
Quick-fix
Update the capacity to the number of provided elements. For collection expressions, the quick-fix can also remove the with(...) element if the explicit capacity is not needed.
19 June 2026