Home  • Programming • C#.NET

How to calculate sum of a DataTable's Column in LINQ?

csharp-dot-net If untyped (replace int with the correct data type):
var sum = table.AsEnumerable().Sum(x=>x.Field<int>(3));
or
var sum = table.AsEnumerable().Sum(x=>x.Field<int>("SomeProperty"));
If typed:
 var sum = table.Sum(x=>x.SomeProperty);

Comments 0


Share

Copyright © 2024. Powered by Intellect Software Ltd