473,324 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

ArrayList ToArray() throwing exception (concatenate double[])


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
Oct 23 '07 #1
3 2954
Michael Howes <mh****@xfortebio.comwrote:
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?
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.

--
Jon Skeet - <sk***@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
Oct 23 '07 #2
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
--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"Michael Howes" <mh****@xfortebio.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>
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

Oct 23 '07 #3
Michael Howes wrote:
>
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))

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

--
Göran Andersson
_____
http://www.guffa.com
Oct 23 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark Oueis | last post by:
ArrayList arrayList = new ArrayList(); foreach (Blabla bla in Blablas) { arrayList.Add(Convert.ToInt32(blabla.something)); } so far this works great.. but now
2
by: Sunny | last post by:
Hi, I have a small function, that returns a string, inside the function, there is an arraylist, being processed. At the end of the function all the elements of the ArrayList are copied to my...
4
by: Derrick | last post by:
If i have an ArrayList, add a bunch of MyClass classes to it, how do I get a MyClass out of it? I've tried: MyClass clses = ArrayList.ToArray(typeof(MyClass)); but get errors about not being...
40
by: Kevin Yu | last post by:
is it a bad programming design to throw exception in the try block then catch it??
2
by: Dirk | last post by:
Hello The following code does not work ArrayList __gc* allControls = new ArrayList(); ..... // put some Controls in allControls .... Control __gc* arr = dynamic_cast<Control...
5
by: KJ | last post by:
This is kind of hard to explain but I have a The controls are created with CreateChildControls(). Now let say I click a button and an error occurs in the control. If I throw it up it goes back...
10
by: mttc | last post by:
I read articles that suggest preventing delete by throwing Exception from RowDeleting Event. I not understand where I can catch this Error?
1
by: Tedmond | last post by:
Dear all, How can I convert a list of items from ArrayList into an array of non system type objects? e.g. The following codes have error: public class myClass { int i;
2
by: Samuel R. Neff | last post by:
I'm using a quasi open-source project and am running into an exception in double.Parse which is effectively this: double.Parse(double.MinValue.ToString()) System.OverflowException: Value was...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.