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

后端 未结 4 1893
忘了有多久
忘了有多久 2021-02-11 14:31

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:43

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

提交回复
热议问题