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)

4.75/5 (4 votes)
18 Jan 2012CPOL 16.3K  
I would just use:string.Join(,, cities.Select(c=>c.Name))Since Version 4 of the Framework there is an overloaded versions of string.Join for IEnumerable too. It uses a StringBuilder internally and doesn't insert a seperator after the last element as well.I could't find the Join method...

I would just use:


C#
string.Join(",", cities.Select(c=>c.Name))

Since Version 4 of the Framework there is an overloaded versions of string.Join for IEnumerable too. It uses a StringBuilder internally and doesn't insert a seperator after the last element as well.


I could't find the Join method you mentioned in your last example with the search of my Reflector. Must be an extension to IList of string?! Where is it defined?

License

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