Programming is about conceptualizing well, it’s about writing significant code. It’s not about typing less. What you’re trying to do is make the code unreadable and create maintenance issues. Don’t do it. Make it readable.
But you may have an engineering problem there. I can’t give details because the question doesn’t give details.
If you have variables with the same prefix in the name and then a sequential number, maybe you should change this. You could use a
pictureBox[i]
And a
Carta[i]
I put in the Github for future reference.
Even if you want to insist on doing it this way it’s to work as you’re thinking of doing, as long as these CartaX
are of a type by reference because array shall have a reference to the equal data in InformationLetters.CartaX
(where X
there is only a convention to show that is the number of each). They are accessing the same object, therefore changing in one place changes in the other.
If type is by value only if day C# allows use ref
in the element of array. Today I would have to create an infrastructure that would handle it, I don’t think it’s worth the effort.
If the problem is the number of lines, each if
there is occupying 4 lines, but it is possible to occupy 1, and if bobear becomes more readable.
I don’t know the whole code, nor does it have a clear context, but I wonder if the loop of the variable j
is necessary. If there is an individual treatment for each value of j
, he is redundant.
Everything is a matter of concept, write the code to show what you want, not to have fewer lines. If you need to handle items individually do so, if you need to treat items as a sequence (array), then set them so to use so afterwards.
for
s withif
s for all indices are always wrong at the design level. I suggest you do not put the code as picture. See here why. TheInformationLetter
was set where and how? The same question to theCartasInformacao
– Isac