Programming is about conceptualizing well, it's about writing meaningful codes. It's not about typing less. What you are trying to do is make the code unreadable and create maintenance problems. Do not do this. Make it readable.
But you may have an engineering problem there. I can not give details because the question does not give details.
If you have variables with the same prefix in the name and then a sequential number, it might be the case to change this. You could use a
pictureBox[i]
And one
Carta[i]
Even if you want to insist on doing this is to function as you are thinking of doing, as long as those Cartax
are of a type by reference, because in array you will have a reference for the equal data has InformationLetters.Cartax
(where x
there is only one convention to show that is the number of each). They are accessing the same object, so changing it in one place changes the other.
If the type is by value only if a C # day allows you to use ref
in the array element. Today I would have to create an infrastructure that would deal with this, I do not 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 do not know the whole code, nor does it have a clear context, but I wonder if the loop of the j
variable is necessary. If there is an individual treatment for each value of j
, it is redundant.
It's all a matter of concept, write the code to show what you want, not to have fewer lines. If you need to handle items individually then do so, if you need to treat items as a sequence ( array ), then set them to use so later.