Skip to content

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

Updated: at 02:12 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));

 

Check out the ORM (Object Relational Mapper) PRISMA. The database access method I use in all my projects