Click here to Skip to main content
15,877,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one ArrayList I want to make string ( May be comma seperated) how I can do this?
I dont want to use FOR loop.
Please help me.

Thanks in advance.

Try something like
<br />
string[] sArray = (string[])pArrayList.ToArray(typeof(string));<br />
string Result = string.Join(sSeparator, sArray, 0, sArray.Length);<br />
Share this answer
sushil_gupta 14-Jun-11 2:48am    
When I am tring this getting an error in first statement
Timberbird 14-Jun-11 3:02am    
You may get this exception if your ArrayList contains values other than strings. Is that the case? If yes, try changing the code above this way:

object[] pArray = pArrayList.ToArray();
string Result = string.Join(sSeparator, pArray);
Dalek Dave 14-Jun-11 3:18am    
Good Call.

string str = arr.Cast<string>().Aggregate((str1, str2) => str1 + "," + str2);

will give you comma seprated string but make sure that your arraylist contains all the string
Share this answer
Dalek Dave 14-Jun-11 3:18am    
Try System.String.Concat(myArrayList.ToArray());
Share this answer
sushil_gupta 14-Jun-11 2:49am    
It worked. But it is combining all the value after the another.
Dalek Dave 14-Jun-11 3:18am    
Good Answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900