我怎么...写linq查询来汇总colelction中的coloumn(数据表) [英] How do i...write linq query to sum the coloumn in colelction(data table )

查看:81
本文介绍了我怎么...写linq查询来汇总colelction中的coloumn(数据表)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 linq查询汇总(数据表)中一列的总和,其中包含多列

id金额状态
1 1234 c
2 4321 e
3 100 s
4 900 q
5 1000 m

i想要输出结果为字符串,其总和为(1234 + 4321 + 100 + 900 + 1000 )= 75555





我的尝试:



i希望输出结果为字符串,其总和为(1234 + 4321 + 100 + 900 + 1000)= 75555

解决方案

简单:

  int  sum = yourDataTable.AsEnumerable()。Sum(r = >  r.Field< int>(  amount)); 


linq query to sum of one column in a collection (data table) which has multiple columns

id     amount      status
1      1234          c
2       4321         e
3        100         s
4       900          q
5      1000          m

i want a output result as string which sum of (1234+4321+100+900+1000)= 75555



What I have tried:

i want a output result as string which sum of (1234+4321+100+900+1000)= 75555

解决方案

Simple:

int sum = yourDataTable.AsEnumerable().Sum(r => r.Field<int>("amount"));


这篇关于我怎么...写linq查询来汇总colelction中的coloumn(数据表)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆