Add all the items cost in a list [Resolved]

Posted by Nagukothapalli under ASP.NET on 1/30/2013 | Points: 10 | Views : 1706 | Status : [Member] | Replies : 2
hi all ,
i need to implement the sum all the items cost in a list , i want to use linq
thanks in advance




Responses

Posted by: Saratvaddilli on: 1/31/2013 [Member] [MVP] Bronze | Points: 50

Up
0
Down

Resolved
Once check this piece of code

 var VarCost = myList.GroupBy(x => x.ItemType).Select(g => new { ItemType= g.Key, Sum = g.Sum(x => x.ItemAmount) });


you will get the cost of items in the list based on the items

hope this will helpful to you

Thanks and Regards
V.SaratChand
Show difficulties that how difficult you are

Nagukothapalli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kundan64 on: 1/31/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
If you want to Sum of all the items Cost then use the Query:

var totalCost = Items.Select(k => k.cost).Sum()


Nagukothapalli, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response