0
I always had a question regarding the code blocks below, which would behave faster taking into account the service:
foreach(var t in listaT)
{
using(TService service = new Tservice())
{
t = service.Find(t.Id)
t.ValorPontuacao = Math.Round(Convert.ToDecimal((t.ValorR / t.Valor) * t.ValorP), 2, MidpointRounding.ToEven);
listT.Add(t);
};
}
using(TService service = new Tservice())
{
foreach(var t in listaT)
{
t = service.Find(t.Id);
t.ValorPontuacao = Math.Round(Convert.ToDecimal((t.ValorR / t.Valor) * t.ValorP), 2, MidpointRounding.ToEven);
listT.Add(t);
}
}
The excerpt of code is only one example, I would like to know which is more performative, knowing that the second example would give "less" work for Garbage Collector. Making it clear that the TService
is an overload of AbstractService<TDAO,T>
, it is worth noting that the class T
is only an example and the list will be manipulated later.
I understand, sorry for exemplifying a bad code. I will add more details in the code to improve the question.
– user2992172