473,378 Members | 1,369 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,378 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 5104
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.