Fastest way to convert string array to double array?

Array.ConvertAll(sarray.Split(','), Double.Parse);

Unlike LINQ's .ToArray(), this pre-allocates a correctly-sized array and doesn't do any resizing.
This should be indistinguishable from a hand-rolled loop.


When I used:

double[] doubles = Array.ConvertAll(sarray.split(','), Double.Parse);

I got this error:

The type arguments for method 'System.Array.ConvertAll(TInput[], System.Converter)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

But it worked when I did this:

double[] doubles = Array.ConvertAll(sarray.split(','), new Converter<string, double>(Double.Parse));

Tags:

C#

.Net

Linq