【发布时间】:2011-05-23 01:59:35
【问题描述】:
如果你看它在底部(内部)foreach 语句中调用方法 FindChildControls,因为它来自 foreach,这是否会使其递归或迭代?
谢谢!
public static IEnumerable<T> FindChildControls<T>(this ControlCollection controlCollection) where T: class
{
foreach(Control control in controlCollection)
{
if(control is T)
{
yield return control as T;
}
foreach(T type in control.Controls.FindChildControls<T>())
{
yield return type;
}
}
}
【问题讨论】:
-
public static不是static public -
@Saeed,两者都是有效的并且表示相同的东西,但
public static确实更常见。 -
@Saeed 我是那个编写原始代码的人,当时我正处于一种风格上,并将静态放在任何事情之前。谢天谢地,我已经恢复到正常的
blah static模式。