public static bool AllNodesChecked(TreeNodeCollection nodes)
{
foreach (TreeNode node in nodes)
{
if (!node.Checked)
{
return false;
}
AllNodesChecked(node.Nodes);
}
return true;
}
Test tree is
A1(checked) -> B1(unchecked)
A2(checked)
A3(checked)
but it isn’t returning when it hits node B1.
EDIT: Thank you all for helping my tired brain. Recursion should only be attempted early in the day after a cold shower.
You are ignoring the return value of
AllNodesCheckedin the recursive call:The
returnstatement only returns from the current method in the call stack to the immediate caller. It doesn’t suddenly return from all other calls above in the call stack.