我得到這個荒謬的錯誤「unreachablecode檢測」,並在適當的visibiliity顯然一切都在...檢測到無法檢測到的代碼?
這裏是代碼..
int lastAppNum = 0;
//load the xml document
XmlDocument xdoc = new XmlDocument();
xdoc.Load(GlobalVars.strXMLPath);
//add a app node
XmlNode newApp = xdoc.CreateNode(XmlNodeType.Element, "app", null);
//add the app number - this will be used in order to easily identify the app details (used for overwriting/saving)
XmlAttribute newNum = xdoc.CreateAttribute("num");
//in order to create a new number - search the last num and add one to it
foreach (XmlNode xmlAppChild in xdoc.ChildNodes)
{
//if there are existing child nodes
if (true)
{
//get the last childs num attribute
lastAppNum = Convert.ToInt32(xmlAppChild.LastChild.Attributes["num"].Value);
//add +1 to the last app num
lastAppNum++;
//add the new value to the attribute
newNum.InnerText = lastAppNum.ToString();
break;
}else{
//if there isnt an existing child node - set the num to 1
lastAppNum = 1; <<where the error happens
newNum.InnerText = lastAppNum.ToString();
break;
}
}
任何人都不會有什麼事的想法的?我想也許是因爲缺乏一個「休息」,所以我在這裏扔了兩個(我在一個表格上看到了什麼是解決方案),但是無論哪種方式都沒有關係,並且錯誤仍在發生。任何建議都會很棒。
'如果(真)'可能永遠是'真':) –
@ user3302467:如果您設置正確的警告級別,無法訪問的代碼不是錯誤。這更多的是警告用戶,你可能寫了一些沒有意圖的東西。 –
難道那不是所有的警告?爲什麼他們都應該被視爲錯誤? – paulm