this is the code:
private TreeNode GetTopLevelNode(TreeNode childNode)
{
if (childNode == null)
throw new ArgumentNullException("childNode", "childNode is null.");
if (childNode.Parent == null) return childNode;
TreeNode node = childNode;
while (true)
{
if (node.Parent == null)
{
return node;
}
node = node.Parent;
}
}
in the while loop, only if node.Parent == null, a node will be returned,
why the compiler doesn't report "not all code paths return a value" error?
if the 'node.Parent == null' can't be satisfied , then no tree node will be returned. The compiler can't detect this situation?