In VB.NET, let\'s assume I have the following Structure:
Public Structure Product Public ItemNo As Int32 Public Description As String Public Cost As
The built in Sum method does this already.
In VB it looks like this:
ProductList.Sum(Function(item) item.Cost)
In C# it looks like this:
ProductsList.Sum( (item) => item.Cost);
One way would be:
Dim s = (From p As Product In products Select p.Cost).Sum()