Converting Array or List of data to String => made easy! (C#, MVC3, LINQ)






2.33/5 (3 votes)
If you're stuck with .NET 3.5, you can use the Aggregate extension method[^]:string cities_string = cities.Aggregate(new StringBuilder(), (sb, c) =>{ if (0 != sb.Length) sb.Append(", "); sb.Append(c.Name); return sb;}, sb => sb.ToString());
If you're stuck with .NET 3.5, you can use the Aggregate extension method[^]:
string cities_string = cities.Aggregate(new StringBuilder(), (sb, c) =>
{
if (0 != sb.Length) sb.Append(", ");
sb.Append(c.Name);
return sb;
}, sb => sb.ToString());