473,320 Members | 1,794 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,320 software developers and data experts.

ArrayList ToArray Cast throwing exception

ArrayList arrayList = new ArrayList();

foreach (Blabla bla in Blablas)
{
arrayList.Add(Convert.ToInt32(blabla.something));
}

so far this works great..
but now

int[] intArray = (int[])includedDevices.ToArray(typeof(int)));

throws System.InvalidCastException: At least one element in the source
array could not be cast down to the destination array type.

i've also tried
int[] intArray = (int[])includedDevices.ToArray(typeof(System.Int32)));

same thing

What's the issue here? I'm doing everything right

Mark
Jul 21 '05 #1
2 5100
Mark Oueis <ma*******@hotmail.com> wrote:
ArrayList arrayList = new ArrayList();

foreach (Blabla bla in Blablas)
{
arrayList.Add(Convert.ToInt32(blabla.something));
}

so far this works great..
but now

int[] intArray = (int[])includedDevices.ToArray(typeof(int)));

throws System.InvalidCastException: At least one element in the source
array could not be cast down to the destination array type.

i've also tried
int[] intArray = (int[])includedDevices.ToArray(typeof(System.Int32)));

same thing

What's the issue here? I'm doing everything right


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
I am sure it is just a typing error,
but you add the System.Int32 instances to 'arrayList'
and you are trying to cast them into System.Int32 [] from 'includedDevices'.
Are you mixing up two different instances?
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Mark Oueis" <ma*******@hotmail.com> wrote in message
news:b1*************************@posting.google.co m...
ArrayList arrayList = new ArrayList();

foreach (Blabla bla in Blablas)
{
arrayList.Add(Convert.ToInt32(blabla.something));
}

so far this works great..
but now

int[] intArray = (int[])includedDevices.ToArray(typeof(int)));

throws System.InvalidCastException: At least one element in the source
array could not be cast down to the destination array type.

i've also tried
int[] intArray = (int[])includedDevices.ToArray(typeof(System.Int32)));

same thing

What's the issue here? I'm doing everything right

Mark

Jul 21 '05 #3

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

Similar topics

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...
2
by: Dylan Parry | last post by:
Hi, I have an ArrayList that contains objects of type "Client", and I would like to convert the ArrayList to a regular Array before returning it from a method. I would like to return it as an...
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...
2
by: Steve | last post by:
I have a very simple datatable of 1 column which I retrieve from a database, call it 'data'. Dim data As Data.DataTable data = myobject.mymethod(parameter) I want to now turn this 'data' into...
2
by: Russ Green | last post by:
I am currently working on a small VB.NET utility that accesses the Microstation VBA object model via COM. I have this code which I am trying to get to work... The key bits of information are ...
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: Earl | last post by:
I'm trying to do a cast and I'm not sure where I'm going wrong here. I load up the ColorExtIntID column (int) into a list array (no problem there). For binding to a 3rd party component, it has to...
14
by: budy_ludy | last post by:
Hi All, I am new to vb .net, I have an ArrayList and i store class objects in it, and later i want to retrieve each ArrayList items and type cast to the class, How can it be done ? I used...
3
by: Michael Howes | last post by:
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: 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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.