开发者

C# string[]ToList then ToString() with Delimeter [duplicate]

This question already exists: Closed 12 years ago.

Possible Duplicate:

开发者_C百科 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜