Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的 C# 项目中有一组 DataRow 对象,我想从中汇总各个字段。
我注意到 DataRow[].Sum<> 函数,而不是遍历每一行并汇总我自己的总和,但我正在努力在网上找到有关如何使用它的任何资源。
任何朝着正确方向的指针都会非常有帮助
:) 删除代码示例,因为它是错误的!现在一切正常 - 链接帮助 Marc 欢呼。
那就是 LINQ Sum;并且可以使用:
Sum
var sum = rows.Sum(row => row.Field<int>("SomeColumn")); // use correct data type
(您也可以传入列索引或DataColumn代替字符串)
DataColumn
对于无类型的数据行,或者:
var sum = rows.Sum(row => row.SomeColumn);
对于类型化的数据行。
MSDN对此有完整的文档;例如,这是我在上面的示例中使用的重载。
这是我在 Datatable 的 DataRow 中使用总和数字字段的方法。
我为谁担忧。
DataTable retrieveData = GetData(); decimal value = 0; var total = retrieveData.Rows[i].ItemArray.Sum(row => decimal.TryParse(row.ToString(), out value) ? decimal.Parse(row.ToString()) : 0);
我正在学习 perl 模块 IPC::Run。在阅读 cpan 文档时,我遇到了'<pipe'. 我写了一个小程序。在执行时它总是挂起。
'<pipe'
我编写的代码:这只是 cpan doc 的副本。
local (*IN); @cat = ('cat') $h = star
0 c# - 开发网络/移动聊天系统
0 php - php登录检查代码不起作用
2 c++ - 你在哪里下载 C++ 软件?
1 angularjs - 为同域请求设置访问控制标头
3 sync - rsync --delete-after 问题
1 php - Facebook登录变得不稳定
Reference php × 1429865 c/c++ × 756500 nginx × 49975 mongodb × 159057 mybatis × 3233 anaconda × 13410 pycharm × 14671 python × 1902243 vscode × 56040 docker × 110988 github × 49000 flask × 49129 ffmpeg × 24037 jmeter × 16910 matplotlib × 63493 bootstrap × 54641