Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

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

By , 18 Jan 2012
Rate this:
Please Sign up or sign in to vote.

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 you mentioned in your last example with the search of my Reflector. Must be an extension to IList of string?! Where is it defined?


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

About the Author

Web Developer
Germany Germany
No Biography provided

Comments and Discussions

GeneralReason for my vote of 5 this is the best option, clean and g... Pinmemberalbertoleon2-Feb-12 10:50 
GeneralYou are right, it uses extension library 'PGK.Extensions' fr... PinmemberMikhail T. (devnoob)19-Jan-12 8:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140421.2 | Last Updated 18 Jan 2012
Article Copyright 2012 by wgross
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid