我刚刚开始阅读 LINQ,我想开始将它整合到我的代码中.我知道如何通过Foreach"遍历行或在特定列上执行 compute.sum 来计算 DataTable 列的总和.如何使用 LINQ to DataSet 进行等效操作?
I'm just started to read up on LINQ and I want to start incorporating it into my code. I know how to compute the sum of a DataTable's column by either "Foreach"-ing through the rows or by doing a compute.sum on the specific column. How do I do the equivalent with LINQ to DataSet?
如果没有类型(将 int 替换为正确的数据类型):
If untyped (replace int with the correct data type):
var sum = table.AsEnumerable().Sum(x=>x.Field<int>(3));
或:
var sum = table.AsEnumerable().Sum(x=>x.Field<int>("SomeProperty"));
如果输入:
var sum = table.Sum(x=>x.SomeProperty);
这篇关于如何计算 LINQ 中 DataTable 的列的总和(到数据集)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
车牌检测有哪些好的算法?What are good algorithms for vehicle license plate detection?(车牌检测有哪些好的算法?)
Unity中图像的onClick事件onClick event for Image in Unity(Unity中图像的onClick事件)
运行总 C#Running Total C#(运行总 C#)
单击带有 JAvascript.ASP.NET C# 的超链接时删除目录Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(单击带有 JAvascript.ASP.NET C# 的超链接时删除目录)
asp.net listview 在单击时突出显示行asp.net listview highlight row on click(asp.net listview 在单击时突出显示行)
从函数调用按钮 OnClickCalling A Button OnClick from a function(从函数调用按钮 OnClick)