I would put repeating elements in arrays and then move them.
TextBox[] foos = new TextBox[] { foo1, foo2, foo3, };
TextBox[] bars = new TextBox[] { bar1, bar2, bar3, };
for (int i = 0; i <= 10; i++)
if (foos[i].Text.Length != 0 && bars[i].Text.Length != 0)
output.Text += myStrings[i] + "/" + foos[i].Text + bars[i].Text;
Of course, if the elements are really named sequentially, you can populate the arrays by looking at the controls from the collection of Form controls named "foo" + number.ToString ().
source
share