65.9K
CodeProject is changing. Read more.
Home

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

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.33/5 (3 votes)

Jan 24, 2012

CPOL
viewsIcon

9610

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