Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 17-Jul-18 5:19am

1 solution

Simple:
C#
int sum = yourDataTable.AsEnumerable().Sum(r => r.Field<int>("amount"));
 
Share this answer
 
v2
Comments
George Swan 17-Jul-18 14:17pm    
I thought the OP wanted the output as a string!!
Richard Deeming 17-Jul-18 14:18pm    
If the OP can't work out how to convert an int to a string, there's no hope for any of us! :D
George Swan 17-Jul-18 14:20pm    
Ho ho

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900