How can the following Generic List be summed up by total cost? Meaning is it possible to add both costs below to get a total?
Model:
public class Product
{
public string Name {get;set;}
public int Cost {get;set;}
}
Now I want to use that model in a Generic list like this:
public void GetTotal()
{
IList<Product> listOfJediProducts = new List<Product>();
Product newProduct1 = new Product();
newProduct1.Name = "LightSaber";
newProduct1.Cost = 1500;
listOfJediProducts.Add(newProduct1);
Product newProduct2 = new Product();
newProduct2.Name = "R2RobotSpec9";
newProduct2.Cost = 5000;
listOfJediProducts.Add(newProduct2);
}
How would I return say a Total for Products in list?