Generating Comma Separated Values

后端 未结 3 1692
离开以前
离开以前 2021-02-15 01:56

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

3条回答
  •  伪装坚强ぢ
    2021-02-15 02:41

    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);
    

提交回复
热议问题