如何在C#中使用Linq将函数应用于列表中的每个元素,如python中的方法reduce()?
Cᴏʀ*_*ᴏʀʏ 11
假设您正在讨论此reduce函数,C#和LINQ中的等价物是Enumerable.Aggregate.
快速举例:
var list = Enumerable.Range(5, 3); // [5, 6, 7]
Console.WriteLine("Aggregation: {0}", list.Aggregate((a, b) => (a + b)));
// Result is "Aggregation: 18"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
968 次 |
| 最近记录: |