Join an ArrayList

G

Guest

I need to join the elements of an arraylist into a comma delimited list and
have been doing the following

string[] x = new string[myArrayList.Count];
myArrayList.CopyTo(x);
string.join(",",x);

I tried string.join(",",myArrayList.ToArray(typeof(string))); but the
compiler complained about converting from an object to a string array.

Is there another, i.e. shorter, way to do this?

Kev
 
F

Frank Dzaebel

Hi kevin,
I need to join the elements of an arraylist into a comma delimited
list and have been doing the following
I tried string.join(",",myArrayList.ToArray(typeof(string))); but the
compiler complained about converting from an object to a string array.

ok, if you have an ArrayList then use this to
get a (joined) string "s" from it:

string s = string.Join(",", myArrayList.ToArray(typeof(string)) as
string[]);


ciao Frank
 
G

Guest

That did it. Thanks

Frank Dzaebel said:
Hi kevin,
I need to join the elements of an arraylist into a comma delimited
list and have been doing the following
I tried string.join(",",myArrayList.ToArray(typeof(string))); but the
compiler complained about converting from an object to a string array.

ok, if you have an ArrayList then use this to
get a (joined) string "s" from it:

string s = string.Join(",", myArrayList.ToArray(typeof(string)) as
string[]);


ciao Frank
 

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