Fastest way to convert a list of strings into a single concatenated string?

后端 未结 7 2077
一向
一向 2021-02-14 21:27

I have some LINQ code that generates a list of strings, like this:

var data = from a in someOtherList
           orderby a
           select FunctionThatReturnsS         


        
7条回答
  •  梦谈多话
    2021-02-14 21:59

    Use "Aggregate" like this:

        List strings = new List() {"bob", "steve", "jane"};
        string result = strings.Aggregate((working, next) => working + next);
        Console.WriteLine(result);
    

    Note: Aggregate is in the System.Linq namespace as an extension method.

提交回复
热议问题