The real reason is that the designers simply didn't feel that the benefit of this little bit of syntactic sugar was worth the effort of implementing or that it might cause some confusion.
There is a slight issue if you want create a List<int>
. What should this mean?
var list = new List<int>(10);
Is that a new list with capacity 10, or a new list containing a single element, 10?
Spoiler, if you're not sure how the compiler will interpret it:
It will be treated as a capacity. If T
is anything other than int
, it will be treated as a single element. It would also be treated as a single item if you specify the parameter name—List<int>(items:10)
In any case, there's no reason you couldn't just write:
var list = new List<string>(new[] { "test string 1", "test string 2" });
This is exactly what the compiler would do if there had been a constructor that provided a params
argument, and this is indeed slightly more efficient than the collection initializer. Having to type a few extra characters to accomplish this really isn't that big of a deal in the grand scheme of things.