Answer the question
In order to leave comments, you need to log in
How to implement a method that would return the sum of a List?
Good afternoon!
Please tell me in which direction to dig to implement the following task:
There is a class:
internal class DataDevice
{
public int Rate { get; set; }
public int[] Indication { get; set; }
public double[] Price { get; set; }
}
internal DataDevice(int rate, int[] indication, double[] price)
{
Rate = rate;
Indication = indication;
Price = price;
}
List<DataDevice> s = new List<DataDevice> {
new DataDevice(2, new int[2] { 1025, 1145 }, new double[2] { 4.05, 84.05 })
new DataDevice(2, new int[2] { 1126, 1214 }, new double[2] { 4.05, 84.05 })
new DataDevice(2, new int[2] { 1265, 1351 }, new double[2] { 4.05, 84.05 })
};
Double summ = s.TotalAmount();
Answer the question
In order to leave comments, you need to log in
Judging by your comments, I can assume such a decision
public double TotalAmount(List<DataDevice> data)
{
double sum = 0;;
for(var i = 1; i < data.Count; data++)
{
sum += (data[i].Indication[0] - data[i-1].Indication[0]) * data[i].Price[0] + (data[i].Indication[1] - data[i-1].Indication[1]) * data[i].Price[1];
tempValue.Add(sumItem);
}
return sum;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question