Estou tentando somar alguns valores ao longo de um ano. Meu código é executado por dia, então preciso somar esses valores após os cálculos. O objetivo é então exportá-los de volta para SQL. Já montei uma tabela e consegui exportar alguns valores para a tabela, mas apenas os valores diários e ainda não os anuais.
// YEAR OVERVIEW
OptResultDataYear optResultDataYear = new OptResultDataYear();
// Variations in price
List<float> varprijs = new List<float> { 0.06f, 0.08f, 0.10f, 0.12f, 0.14f, 0.16f, 0.18f };
// Create dictionaries for storing the values
Dictionary<float, OptResultYear> yearlyResults = varPrijs.ToDictionary(co => co, co => new OptResultYear { AfdelingId = afd.AfdelingsId, variatiePrijs = co });
// SQL output
OptResultYear optResultYear= new OptResultYear();
for (DateTime date = startYear; date < endYear; date = date.AddDays(1))
{
foreach (float co in varprijs)
{
// Calculate the optimal results with the varPrijs
ResultScenDay optResultvar = await DayCalc.RunOcapOptimaalDayAsync(afd.AfdelingsId, date, 3600, (int)ScenarioType.Optimal, co, null); // per dag met uurdata.
// Analyze the code
optResultYear = analysePeriode.FillOptResultYear(afd.AfdelingsId, kenm.TeeltOppHa, date, optResultvar, co, null);
// Collect the required values
yearlyResults[co].OptTotalDos += (float)optResultYear.OptTotalDos;
yearlyResults[co].OptDos1 += (float)optResultYear.OptDos1;
yearlyResults[co].OptDos2 += (float)optResultYear.OptDos2;
yearlyResults[co].OptCost += (float)optResultYear.OptCost;
yearlyResults[co].OptProductie += (float)optResultYear.OptProductie;
yearlyResultsCO2[co].OptConcLp += (float)optResultYear.OptConcLp;
// Set the date for the last entry
yearlyResultsCO2[co].Datum = date;
}
}
Os valores à direita (optResultYear.) possuem valores e são calculados conforme necessário. No entanto, ao adicioná-los ao meu dicionário, obtenho apenas valores NULL.
Alguém sabe como resolver isso ou conhece uma opção melhor?