Tuesday, November 23, 2010

Creating a delimiter separated list from list of strings

When you have a list of strings like IList<string> of IEnumerable<string> and you want to convert it to for example a comma separated list you can easily do that with the String.Join method.
List<string> list = new List<string>() { "A" , "B", "C", "D", "E" };
string commaSeparated = String.Join(",", list.ToArray());
The output will be like this:
This is an easy and clean way to create a delimiter separeated list of strings.

No comments:

Post a Comment