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 a while loop, only if node.Parent == null returns node,
why does the compiler not report the error "not all path codes return a value"?
if 'node.Parent == null' cannot be satisfied, then the node tree will not be returned. The compiler cannot detect this situation?
Since you are using while(true){, there is no other way to exit the loop than using return. if node.parent == nullit cannot be done, then it will be an infinite loop. Thus, it is impossible to go past the loop without returning, and the compiler does not complain.
while(true){
node.parent == null
, , , null TreeNode, , ?
TreeNode
: , .
. : , , , .
, , -, . , , ββ . , (1) , (2) , (3) .
# . , , "while (true)" , "", . , " " " , , ". , " , ", .
. , - , if (node.Parent == null) true.
if (node.Parent == null)
true
, .
, wil , - null. , .
, TreeNode , . , , . , , undefined , .
Source: https://habr.com/ru/post/1728144/More articles:Silverlight: passing a complex object between pages - c #https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1728140/aspnet-passing-arguments-to-the-server-on-button-click&usg=ALkJrhi8Zgoiq-ykxJzpx7royC_lDyb__gBoost Library for RTTI - c ++CSS IE6 float right - htmlHow to change FxCop language? - internationalizationDo metaphorical metafile tags βinterruptβ PHP sessions? - htmlhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1728146/good-resources-to-learn-about-models-of-computation&usg=ALkJrhiI6q_yYdSvJJ97zppI-yGt6goalQRegex for matching alternating sequences - javaHow to get ImageButton in Android to automatically scale based on screen density? - androidHow to determine the order of displayed columns in a datagridview bound to a data source - c #All Articles