string.Join 和 Linq LINQ Aggregate 返回
C#论坛
老数据
2027
悬赏:0 飞吻
1.Aggregate
var chars = new []{"a","b","c", "d"};
var csv = chars.Aggregate( (a,b) => a + ',' + b);
Console.WriteLine(csv); // 输出 a,b,c,d2.string.join一样可以实现上面的效果
var chars = new []{"a","b","c", "d"};
var csv = string.join(",",chars );
Console.WriteLine(csv); // 输出 a,b,c,d总结:Aggregate 看起来和string.Join一样,不过Aggregate 功能更加齐全
下面的例子string.Join就实现不子
var nums = new[]{1,2,3,4};
var sum = nums.Aggregate( (a,b) => a + b);
Console.WriteLine(sum); // 输出10