Anu Anu - 3 months ago 20
Vb.net Question

Sum of list item value in GenericList in Vb.net

I have generic list -GasPropList - in that i want the sum of the all individual items value.
All Varaibles are in Double datatype.

For Each gasprop In GasPropList
gasprop.OUTGi = gasprop.NameVal * gasprop.GasGi / 100
gasprop.OUTPci = gasprop.NameVal * gasprop.Pci / 100
gasprop.OUTTci = gasprop.NameVal * gasprop.Tci / 100
gasprop.OUTVi = gasprop.NameVal * gasprop.NHVi / 100
gasprop.OUTGVi = gasprop.NameVal * gasprop.GHDVi / 100
Next


From this i want to calculate sum of OUTGi, OUTPi etc.
I saw Linq Sum function, but don't know how to use for my case.

Answer

E.g.

Dim OUTGiSum = GasPropList.Sum(Function(gp) gp.OUTGi)

I'll leave it to you to do the others.