The type parameter 'T' cannot be used with the 'as' operator because
it does not have a class type constraint nor a 'class' constraint
I have the following code. and i get a compile error.
private List<TGetAllControls<T>(Control control)
{
List<Tcontrols = new List<T>();
foreach (Control child in control.Controls)
{
if (child is T)
controls.Add(child as T); // ERROR HERE
if (child.HasChildren)
controls.AddRange(GetAllControls<T>(child));
}
return controls;
}