PC Review


Reply
Thread Tools Rate Thread

Casting an arraylist of integers to a string array

 
 
Earl
Guest
Posts: n/a
 
      18th Jul 2006
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));

.....

}


 
Reply With Quote
 
 
 
 
allfyre
Guest
Posts: n/a
 
      18th Jul 2006
try changing the last line to:

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

 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      18th Jul 2006
Earl <(E-Mail Removed)> wrote:
> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting a string to an array of integers =?Utf-8?B?RGVhdGhTdXJmZXI=?= Microsoft Excel Programming 4 21st Mar 2007 10:34 PM
Re: Casting a String to a single character Array Ken Tucker [MVP] Microsoft VB .NET 0 22nd Jul 2004 02:32 PM
Re: Casting a String to a single character Array Jay B. Harlow [MVP - Outlook] Microsoft VB .NET 0 22nd Jul 2004 02:29 PM
Re: Casting a String to a single character Array Jay B. Harlow [MVP - Outlook] Microsoft VB .NET 0 22nd Jul 2004 02:25 PM
Converting a string of integers to an array/arraylist Graeme Downes Microsoft Dot NET 1 12th Jul 2003 08:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:36 AM.