implicit conversion

A

aqualung

DataTable dt;
ArrayList al = new ArrayList(ds.Tables[0].Rows.Count);

dt = ds.Tables[0];
Int32 i;
for (i = 0; i <= dt.Rows.Count - 1; i++)
{
al.Add(dt.Rows[0]);
}
string[] s;
s = al.ToString();
c.Items = s;



The above code produces an error on the next to last line that says it
can't convert from string to string[]. In VB it works fine without
doing any type of conversion. Any ideas how to work this out?

Thanks much.....
 
M

Mattias Sjögren

The above code produces an error on the next to last line that says it
can't convert from string to string[]. Any ideas how to work this out?

Don't you want to do

s = (string[])al.ToArray(typeof(string));

In VB it works fine without doing any type of conversion.

With option strict off perhaps.




Mattias
 
C

Chris R. Timmons

(e-mail address removed)-spam.invalid (aqualung) wrote in
DataTable dt;
ArrayList al = new ArrayList(ds.Tables[0].Rows.Count);

dt = ds.Tables[0];
Int32 i;
for (i = 0; i <= dt.Rows.Count - 1; i++)
{
al.Add(dt.Rows[0]);
}
string[] s;
s = al.ToString();
c.Items = s;

The above code produces an error on the next to last line that
says it can't convert from string to string[]. In VB it works
fine without doing any type of conversion. Any ideas how to
work this out?


Replace

s = al.ToString();

with

s = (string[]) al.ToArray(typeof(string));

Hope this helps.

Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top