Generic List to String

S

shapper

Hello,

I have a Generic.List and I need to create a string out of it.

Something like: "Item1, Item2, Item 3, ItemN"

How can I do this?

Thanks,
Miguel
 
L

Laurent Bugnion [MVP]

Hi,
Hello,

I have a Generic.List and I need to create a string out of it.

Something like: "Item1, Item2, Item 3, ItemN"

How can I do this?

Thanks,
Miguel

Shortest I can think of is:

List<string> test = new List<string>();
test.Add( "abcd" );
test.Add( "efgh" );
test.Add( "ijkl" );

string[] test2 = test.ToArray();
string test3 = string.Join( ", ", test2 );

HTH,
Laurent
 
K

Karl Seguin [MVP]

test.ToArray().Join(...) :p

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/


Laurent Bugnion said:
Hi,
Hello,

I have a Generic.List and I need to create a string out of it.

Something like: "Item1, Item2, Item 3, ItemN"

How can I do this?

Thanks,
Miguel

Shortest I can think of is:

List<string> test = new List<string>();
test.Add( "abcd" );
test.Add( "efgh" );
test.Add( "ijkl" );

string[] test2 = test.ToArray();
string test3 = string.Join( ", ", test2 );

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 

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

Similar Threads

Generic List 3
Generic List to String 0
Double $.each break label ( please teach me ) 0
String 3
Generic List to Array 2
DataSet to Generic List 1
Generic List 1
Generic List. Remove duplicate 2

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top