-2
I have the following code:
foreach (var lote in collection.ToList())
{
count++;
ushort[] dadosBalanca = new ushort[9];
if (lote.AlvoPasso > ushort.MaxValue)
{
var subtracao = (lote.AlvoPasso - 65536);
dadosBalanca[3] = 1;
if (lote.AlvoPasso > (ushort.MaxValue * 2))
{
subtracao -= 65536;
dadosBalanca[3] = 2; //[OUT37]
if (lote.AlvoPasso > (ushort.MaxValue * 3))
{
subtracao -= 65536;
dadosBalanca[3] = 3; //[OUT37]
if (lote.AlvoPasso > (ushort.MaxValue * 4))
{
subtracao -= 65536;
dadosBalanca[3] = 4; //[OUT37]
}
}
}
dadosBalanca[4] = (ushort)subtracao; //[OUT38]
}
else
{
dadosBalanca[3] = 0; //[OUT37]
dadosBalanca[4] = (ushort)lote.AlvoPasso; //[OUT38]
}
//...
}
This code already works, I would like to suggest improvement.
I see no need to "dry" the code, the same is with the correct syntax. What is the need that you are having?
– Jorge.M
Do you have more code inside the foreach? This is relevant (not the code itself, but the information) because you may want to use a
continue
to decrease the level of indentation.– Jéf Bueno
Although the code works, from the comments in the answers it is clear that the necessary rules have not been defined, so I closed. Can be edited to put the missing parameters and reopened.
– Bacco