Last post Jul 28, 2009 06:26 AM by MetalAsp.Net
Jul 28, 2009 03:16 AMemail@example.com|LINK
Public Name as string
Public IsSpecial as Boolean
Public Amount as Single
I have a collection “AllCustomers” having all customers.
I applied linq on the collection to get special customers as bellow
Dim SpecialCustomers as IEnumarable(of Customer) Select C from AllCustomers where all C. IsSpecial=true
Suppose I am getting all special customers in SpecialCustomers
Now I have to get the sum of Amount of all customers in SpecialCustomers
What is the linq way to do this?
How can I use sum function over IEnumerable to achieve this
Jul 28, 2009 06:26 AM|MetalAsp.Net|LINK
Try something like this:
var result = from c in SpecialCustomers
group c by c.Name into g
Name = g.Key,
Total = g.Sum(s => s.Amount)
It's in C# but hopefully you can translate...