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

Casting an arraylist of integers to a string array

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 then be cast to a string array.

private void PopulateColors()
{

DataView dvColors = new DataView(dtColors);

ArrayList ColorIDList = new ArrayList(dvColors.Count);

Int32 i;

for (i = 0; i <= dvColors.Count - 1; i++)

{

ColorIDList.Add(dvColors[i]["ColorExtIntID"]);

}

Int32 x = fpSpread1.ActiveSheet.ActiveRow.Index;

// this is the invalid cast where I get an exception

string[] sColorIDList = (string[])ColorIDList.ToArray(typeof(Int32));

.....

}
Jul 18 '06 #1
2 1665
try changing the last line to:

string[] sColorIDList = (string[])ColorIDList.ToArray(typeof(string));

Jul 18 '06 #2
Earl <br******@newsgroups.nospamwrote:
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 then be cast to a string array.
It can't. A cast doesn't change the contents, it just provides the
compiler with more information about what is present.

You'll need to create a new string array of the same size, then convert
each int to a string.

--
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
Jul 18 '06 #3

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

Similar topics

6
by: B J H | last post by:
I want to do the following int list; String list; i int; ..... for (i=0; i<int.length, i++_ { list.concat(list); list.concat(" ");
1
by: Graeme Downes | last post by:
I have a string of integer, such as the following: "12 24 12 9 2" and I want to convert this into an array or arraylist which will seperate the string into an array of integers. How do I do...
6
by: Dan V. | last post by:
I would like to create a 2D string list (2D ArrayList ???). I would like to pass in a table or query as a parameter and have both columns transform into a 2D ArrayList. When I sort the one...
4
by: Peter | last post by:
I run into this situation all the time and I'm wondering what is the most efficient way to handle this issue: I'll be pulling data out of a data source and want to load the data into an array so...
1
by: kieran | last post by:
Hi, I have an Arraylist with an undefined number of integers in it. I need to place each of these in a certain sql statement and run it. I then need to store only those integers that return...
3
by: Andy Chen | last post by:
Hi, I have a Hashtable, key is string and value is ArrayList. The problem is I cannot cast the value from object to ArrayList. like this: Hashtable ht = new Hashtable(); ArrayList al = new...
3
by: Martin Arvidsson, Visual Systems AB | last post by:
Hi! I am going crayz, i cant get this to work. and i don't know what the problem is. I have this method public ArrayList ResolveData() { ArrayList workingList = new ArrayList();
5
by: dhyder | last post by:
This project is using .NET and C#. Although my problem is with C# syntax (I think) I didn't see a C# board to post this on. So sorry if this is in the wrong spot. Basically my problem is trying...
13
by: Boon | last post by:
Hello everyone, Consider a "set" of M=N*N integers. In some parts of my program, I want to handle this set as a 1D array of M integers. In other parts of my program, I want to handle this set as...
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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.