Sunday, 12 June 2016

Sum of items from List in C#

Public Class MyList
{
Public  double Amount{get;set;}
//in controller
List<MyList>myList=new List<MyList>();
 myList.add(new List<MyList>()
{
 Amount=10, 
});
 myList.add(new List<MyList>()
 { 
   Amount=20,  }); 
double total = myList.Sum(item => item.Amount);

No comments:

Post a Comment