Generating Comma Separated Values

后端 未结 2 1469
没有蜡笔的小新
没有蜡笔的小新 2021-02-15 02:17

Suppose I have a collection of strings:

\"foo\"
\"bar\"
\"xyz\"

And I would like to generate a comma separated values from the list into someth

2条回答
  •  感情败类
    2021-02-15 02:52

    String.Join is the right answer, but in the case of an IEnumerable, Linq is often shorter than a for loop:

    someStringCollection.Aggregate((first, second) => first + ", " + second);
    

提交回复
热议问题