Or, ProfK's solution in enumerable syntax:
public static IEnumerable<Control> GetControls(Control form) {
foreach (Control childControl in form.Controls) { // Recurse child controls.
foreach (Control grandChild in GetControls(childControl)) {
yield return grandChild;
}
yield return childControl;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…