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?
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?
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.