2014-02-21 4 views
0

나는 .. 여기 연결할 수없는 코드가 감지 되었습니까?

코드입니다 ...이 rediculous 오류가 "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; 

    } 

} 

사람이 세드릭 아이디어의가 있습니까? 나는 아마 그것이 "휴식"의 부족이라고 생각했기 때문에 나는 여기에 두 개를 던졌다. (나는 해결책이 무엇인지를 보았다.) 그러나 그것은 문제가되지 않았고 오류는 여전히 일어나고있다. 어떤 제안이라도 좋을 것입니다.

+6

가'하면'아마 항상 '참 (true)가 될 것이다 아래로도 구현을 변경해야 ':) –

+0

@ user3302467 : 경고 수준을 올바르게 설정하면 연결할 수없는 코드가 오류가 아닙니다. 사용자에게 의도하지 않은 무언가를 썼다는 경고가됩니다. –

+0

모든 경고 사항은 무엇입니까? 왜 모두 오류로 취급해야합니까? – paulm

답변

10

if (true)이 있습니다. 실제로 여기에서 테스트하고 싶은 조건이 있습니까?

if (true) 
{ 
    // this code will always run 
} 
else 
{ 
    // this code will never run 
} 
0

코드

if (true) 

항상 실행되고 실행되는 다른 조건에 기회가 없습니다. 당신은 내가 당신의 의견에 따라 생각 if (true)

이 있기 때문에

+0

ohh와 같은 의미를 갖는 조건으로 변경해야하는 것처럼 보입니다. 그래, 거기에 조건문을 던지는 걸 까먹었 어. 와! – user3302467

+0

도와 드리겠습니다! 대답을 표시하시기 바랍니다 올바른) –

2

else 조건이 실행되지 않습니다, 당신은

if(xdoc.HasChildNodes) 
{ 
    foreach (XmlNode xmlAppChild in xdoc.ChildNodes) 
    {   

     //if there are existing child nodes     
     //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(); 

    } 
}else 
{ 

    //if there isnt an existing child node - set the num to 1 
    lastAppNum = 1; 
    newNum.InnerText = lastAppNum.ToString(); 
} 
관련 문제