Convert a list to a string in C#

IAdapter picture IAdapter · Feb 13, 2011 · Viewed 300k times · Source

How do I convert a list to a string in C#?

When I execute toString on a List object, I get:

System.Collections.Generic.List`1[System.String]

Answer

Øyvind Bråthen picture Øyvind Bråthen · Feb 13, 2011

Maybe you are trying to do

string combindedString = string.Join( ",", myList.ToArray() );

You can replace "," with what you want to split the elements in the list by.

Edit: As mention in the comments you could also do

string combindedString = string.Join( ",", myList);

Reference:

Join<T>(String, IEnumerable<T>) 
Concatenates the members of a collection, using the specified separator between each member.