What's an efficient and hopefully elegant incantation to convert decimal[] to double[]?
I'm working with some fairly large arrays.
2 Answers
double[] doubleArray = Array.ConvertAll(decimalArray, x => (double)x);
2 Comments
Tobias
Would this be faster than
decimalArray.Select(d => (double)d).ToArray()?Artholl
@Tobias I was also interested, so I created some small tests and the answer to your question is yes but how much faster, it depends on those two types and also if you are in Debug or Release - for 20,000,000
decimals ConvertAll lasts in average 628ms in Debug and 245ms in Release and your method lasts 1015ms in Debug and 573ms in Release in average on my computer. ConvertAll also consumes less memory - it handled approx. 80,000,000 floats to doubles and your method only around 30,000,000 before System.OutOfMemoryException was thrown with the same settings. Tested on .NET 4.5