Anu Anu - 1 year ago 89 Question

Sum of list item value in GenericList in

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

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 Source


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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download