DotNet Controls
Posted: Thu Aug 10, 2023 1:07 pm
Karl,
The only thing that I think is wrong with this code is that you are still using an array.
Why not make it a List<System.Windows.Forms.Control> and why not use foreach to enumerate the list?
The array takes more memory than the List<>. The controls are stored in a usual and in the loop the controls are extracted from the usual, which at least requires a type check to see if the usual is indeed an object. Also, the runtime then has to check to see that the object returned from the usual is indeed a control.
If you declare the list like I suggested, then you can be certain that each element is a control.
FYI, the array class already uses a List<>, but that is a List<USUAL>.
Robert
Robert
The only thing that I think is wrong with this code is that you are still using an array.
Why not make it a List<System.Windows.Forms.Control> and why not use foreach to enumerate the list?
The array takes more memory than the List<>. The controls are stored in a usual and in the loop the controls are extracted from the usual, which at least requires a type check to see if the usual is indeed an object. Also, the runtime then has to check to see that the object returned from the usual is indeed a control.
If you declare the list like I suggested, then you can be certain that each element is a control.
FYI, the array class already uses a List<>, but that is a List<USUAL>.
Robert
Robert