Convert String Array Into String – C# LINQ

A couple months ago, I had written some posts on converting String and Char Arrays

Convert a String Array to a Decimal Array using C# or VB.NET

Convert Char Array to String and Vice Versa

Here’s a very simple way if you want to convert a String Array to String using C# LINQ

static void Main(string[] args)
string[] indiaCityVisit = {
"Delhi", "Jodhpur", "Mumbai", "Pune", "Agra",
"Shimla", "Bengaluru", "Mysore", "Ooty",
"Jaipur", "Nagpur", "Amritsar", "Hyderabad",
"Goa", "Ahmedabad" };

string cities = String.Join(",", indiaCityVisit
.Select(s => s.ToString())

LINQ String Array to String

Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal


David Vidmar said...

The LINQ query doesn't do anything here. All the work is done by String.Join.

Anonymous said...

string cities = String.Join(",", indiaCityVisit);