Generic List to String

  • Thread starter Thread starter shapper
  • Start date Start date
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
 
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
 
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
 
Back
Top