I have many double[] that each have a few thousand numbers in them.
I need to concatenate groups of these double arrays into a new set of
double[].
I don't know the total # of points.
I thought it would be fairly easy to add these different double arrays
to different ArrayLists and then use ToArray to get all the numbers back
in one array. Sort of a cheap concatenate so I don't need to loop
through all the points or keep newing larger arrays
when I call ToArray
(double[])yData.ToArray(typeof(double))
I get an exception; "At least one element in the source array could
not be cast down to the destination array type."
Umm..they were all valid doubles in arrays of doubles before being
added to the ArrayList
any ideas what this might be?
thanks
mike
Jon Skeet [C# MVP] - 23 Oct 2007 21:27 GMT
> I have many double[] that each have a few thousand numbers in them.
> I need to concatenate groups of these double arrays into a new set of
[quoted text clipped - 16 lines]
>
> any ideas what this might be?
Did you add the *arrays* to the ArrayList, or each double in turn? If
you're adding the arrays, then ArrayList isn't going to do any
flattening for you, unless you call AddRange instead of Add.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Ignacio Machin ( .NET/ C# MVP ) - 23 Oct 2007 21:32 GMT
Hi,
Well, the message says everything, at least one element could not be
converted to double.
Do manually and see if you find any problem:
foreach( object o in GetElements )
double d = (double) o;
and see if you get an error and where it's located

Signature
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
>
> I have many double[] that each have a few thousand numbers in them.
[quoted text clipped - 20 lines]
> thanks
> mike
Göran Andersson - 23 Oct 2007 21:36 GMT
> I have many double[] that each have a few thousand numbers in them.
> I need to concatenate groups of these double arrays into a new set of
> double[].
> I don't know the total # of points.
Of course you do. Each array has a length, you only have to add them.
> I thought it would be fairly easy to add these different double arrays
> to different ArrayLists and then use ToArray to get all the numbers back
> in one array. Sort of a cheap concatenate so I don't need to loop
> through all the points or keep newing larger arrays
Any method that could do what you are trying to accomplish, would do
exactly what you are trying to avoid doing yourself.
> when I call ToArray
> (double[])yData.ToArray(typeof(double))
[quoted text clipped - 4 lines]
> Umm..they were all valid doubles in arrays of doubles before being
> added to the ArrayList
You can't convert a double array into a double. The ToArray method will
produce an array with the same number of items as the ArrayList has, it
won't expand any arrays in the ArrayList.
Just create an array with the length of the sum of all the arrays that
you want to put in it, then use the CopyTo method to copy the data from
each array into the new array.

Signature
Göran Andersson
_____
http://www.guffa.com