0

Possible Duplicate:
What is the LINQ way to implode/join a string array?

Say I have a linq query that returns a generic list containing a single string element:

//Actually comes from a linq to sql query so I don't actually have the array.
string[] mer = {"cat","dog","fish"};
var k = (from k in mer
         select k);

Is there a quick convenient way to print the results k in a string like: "cat, dog, fish" using projections?

I know I can simply use a foreach loop and += them into a string variable if there isn't a neat way.

Community
  • 1
  • 1
bill
  • 55
  • 2
  • 2
  • 6

1 Answers1

3

Use String.Join() - it allows you to specify a delimiter, and joins a given collection of strings into a single string joined by that delimiting character / string.

It's not Linq but it solves your problem.

Kirk Broadhurst
  • 27,836
  • 16
  • 104
  • 169