Auto-initializing C# lists

.net, c#, collections, list

Solution

In addition to the functional solutions provided (using the static methods on the `Enumerable` class), you can pass an array of `double`s in the constructor.

var tenDoubles = new List<double>(new double[10]);

This works because the default value of an `double` is already 0, and probably performs slightly better.

Problem

I am creating a new C# List (`List<double>`). Is there a way, other than to do a loop over the list, to initialize all the starting values to 0?

Original source