I have this code which casts controls to a TextBox
:
foreach (Control c in Controls)
if (c.GetType() == typeof(TextBox))
(c as TextBox).Clear();
And I would like to encapsulate it in a function, where I pass in the type at runtime. Something like this:
public void ControlClear(ControlCollection controls, Type type) {
foreach (Control c in controls)
if (c.GetType() == type)
(c as ([?])).Clear();
}
ControlClear(Controls, typeof(TextBox));
How can I cast to the type like this?