Skip to content

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

Updated: at 05:05 PM

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

 List<string> strings = new List<string>
{
	<span class="str">&quot;a&quot;</span>,<span class="str">&quot;b&quot;</span>,<span class="str">&quot;c&quot;</span>

};</pre>

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));