aba*_*hev 14 .net c# linq asp.net findcontrol
存在MyControl1.Controls.OfType<RadioButton>()只搜索通最初收集和不进入到孩子.
是否可以使用Enumerable.OfType<T>()或LINQ不使用自己的递归方法找到特定类型的所有子控件?像这样.
dh.*_*dh. 40
我使用扩展方法来展平控件层次结构,然后应用过滤器,以便使用自己的递归方法.
该方法看起来像这样
public static IEnumerable<Control> FlattenChildren(this Control control)
{
var children = control.Controls.Cast<Control>();
return children.SelectMany(c => FlattenChildren(c)).Concat(children);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15346 次 |
| 最近记录: |