问题是,这
Concat将需要一个
IEnumerable<T>而不是一个
IEnumerable<Control>。这应该可以工作:
public static IEnumerable<T> GetAll<T>(this Control control) where T : class{ var controls = control.Controls.Cast<Control>(); return controls.SelectMany(ctrl => GetAll<T>(ctrl)) .Concat(controls.OfType<T>()));}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)