In the following code, How can I pass the type of variable to the nested foreach statement?
getControls is a recursive function that returns a list of controls (wow!)
getControls(String type, Control donde)
var tipos = new List<Type>() { typeof(Button), typeof(KryptonTextBox) };
foreach (Type t in tipos)
{
List<Control> controls = getControls(t.ToString(), this);
foreach (***** c in controls)
{
c.StateCommon.Back.Color1 = Color.White;
}
}
The iterating variable needs to be of a compatible type to the list item types.
Thus the compiler only allows you to write
but inside the foreach block, you can use type casts to call methods of a specific type: