I am working with a WPF in C#. I am using the GetNextControl
method to store all the child controls in a Control.ControlCollection
. I want to loop through the results and fill in only the text boxes. I have thought of two ways to do this, but which would be more efficient:
- Search once and store the results in an
Control.ControlCollection
. - Use a
foreach
loop to go through the collection and use multipleif
/else
statements to find theTextBox
I am looking for and fill in the box with some text.
Or,
- Search and store all the controls in a
Control.ControlCollection
. - Use the find method of the collection to find a
TextBox
with a certain name and fill in some text in theTextBox
.
I think that the first way would be slower because there are more comparisons to make. While the second method uses searching only.