Small LINQ Trick for Converting List<String> to String Text List

Posted by Peter Kellner on February 24, 2010 · 2 mins read

Here is a shorthand way for converting a list of strings defined as follows:

 List<string> strings = new List<string>
 
	{
		"a","b","c"

	};

To something that looks like:

“a:b:c:”

Here is the trick using the foreach syntax:

 var stringBuilder = new StringBuilder();
 strings.ForEach(a=>stringBuilder.AppendFormat("{0}:",a));