Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / programming / string

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

2.33/5 (3 votes)
24 Jan 2012CPOL 9.6K  
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[^]:

C#
string cities_string = cities.Aggregate(new StringBuilder(), (sb, c) =>
{
    if (0 != sb.Length) sb.Append(", ");
    sb.Append(c.Name);
    return sb;
}, sb => sb.ToString());

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)