Appending a string in a loop in effective way

前端 未结 5 2203
孤城傲影
孤城傲影 2020-12-05 21:15

for long time , I always append a string in the following way.

for example if i want to get all the employee names separated by some symbol , in the below example i

5条回答
  •  被撕碎了的回忆
    2020-12-05 21:59

    I like using the aggregate function in linq, such as:

    string[] words = { "one", "two", "three" };
    var res = words.Aggregate((current, next) => current + ", " + next);
    

提交回复
热议问题