.Net - Join together all item of a list in a output string

后端 未结 4 2156
南笙
南笙 2021-02-11 14:13

How can I write a Linq expression (or anything else) that select item from a List and join them together ?

Example

IList data = new List<         


        
4条回答
  •  星月不相逢
    2021-02-11 14:42

    Why not just go with (String.Join Method)

    string joined = String.Join(",", data.ToArray());
    

    But if it has to be LINQ, you could try

    string joinedLinq = data.Aggregate((i, j) => i + "," + j);
    

提交回复
热议问题