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())
.ToArray());
Console.WriteLine(cities);

Console.ReadLine();
}
LINQ String Array to String

2 comments:

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

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

    ReplyDelete