So I have a List<Product> that I need to loop and calculate some stuff. Every Product has propery Price and Tax. What I want to do is to have a method where I can loop throught the list and calculate the total price and the total tax, but I don't want to write to methods for this.
At the moment I have this:
private double calculateTotalPrice()
{
List<Product> temp = this.GetList();
double price = 0;
for(int i = 0; i < Count; i++)
{
price += temp[i].Price;
}
return price;
}
But with this method I need to have one method for calculating Price and another for Tax. Is it possible to change this method so that I can call it and at one moment calculate the Price, and next time I call it to calculate Tax? My hope is to do this without using If-statements but I'm not sure if this is possible.
Appreciate any help.
EDIT: Spelling