Accessing controls using collection is pretty simple in C#. It comes handy when you want to perform group tasks.
I have a panel which contains many text boxes and Labels. Some of the controls used to format the result. Others name start with txt_ and lbl_. Our task is to clear the Text property with “”/null.
We can iterate through panel controls as follows
foreach(Control c in panel_rateSettings.Controls )
{
if ( c.Name.Contains(“txt_”) || c.Name.Contains(“lbl_”))
{
c.Text=null;
}
}
Maybe you can find another use of the control collection.