LINQ to append to a StringBuilder from a String[]

后端 未结 4 809
借酒劲吻你
借酒劲吻你 2020-12-17 00:30

I\'ve got a String array that I\'m wanting to add to a string builder by way of LINQ.

What I\'m basically trying to say is \"For each item in this array, append a li

4条回答
  •  独厮守ぢ
    2020-12-17 01:11

    Use the "ForEach" extension method instead of "Select".

    stringArray.ToList().ForEach(x => stringBuilder.AppendLine(x));
    

    or

    Array.ForEach(stringArray, x => stringBuilder.AppendLine(x));
    

提交回复
热议问题