这是一个代码。
decimal[] men;
for (b.Pradzia();b.Yra();b.Kitas()) // loops through editions
{
men = new decimal[13]; //
for (a.Pradzia();a.Yra();a.Kitas()) // loops through subscribers
{
if (b.ImtiDuomenisL().Kodas == a.ImtiDuomenisP().Kodas) // if edition code matches subscriber code proceed
{
int j = a.ImtiDuomenisP().LaikotarpioPradžia + a.ImtiDuomenisP().LaikotarpioIlgis; // gets the start of subscription +
// the lenght of it.
for (int i = a.ImtiDuomenisP().LaikotarpioPradžia; i <= j; i++)
{
Dictionary<Leidinys, decimal> suma = new Dictionary<Leidinys, decimal>();
if (j <= 12)
{
men[i] += a.ImtiDuomenisP().Kiekis * b.ImtiDuomenisL().Kaina;
}
else
{
men[j - 12] += a.ImtiDuomenisP().Kiekis * b.ImtiDuomenisL().Kaina;
}
suma.Add(b.ImtiDuomenisL(), men[i]); // adds the edition and the sum of it to the dictionary.
}
}
}
}
我从这种方法中得到的是每个月每个版本的总和。出于某些原因,月份为整数。
对于每个月,我都需要确定哪个版本的收入最多。我不知道怎么。
假设你的“j”变量是几个月(你的代码有点混乱)你只需要这样的东西:
int moneyofmonth = 0;
int biggest = 0;
foreach(var month in j)
{
moneyofmonth = //moneyofthismonth using the var "month".
if(moneyofmonth > biggest)
{
biggest = moneyofmonth;
}
}
“最大”将是所有月份中最大的钱。如果你想保存最大的月份,如果保存“月份”变量,它只是在里面创建一个新的变量。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句