2017-03-23 4 views
-1

ich habe keine ahnung, warum es nicht aus der schleife herauskommen kann nach dem erhalt der eigenschaften und mit der break-aussage.
kant raus aus foreach loop

int i = 2; 

foreach (UITestControl con in uIItemCustom.GetChildren()) 
       { 

        Description = new HtmlCell(con); 
        Description.FilterProperties[HtmlCell.PropertyNames.ColumnIndex] = "4"; 
        Date = new HtmlCell(con); 
        Date.FilterProperties[HtmlCell.PropertyNames.ColumnIndex] = "5"; 

       if (TestContext.DataRow["BillableLine"].ToString() == Description.InnerText.ToString() && TestContext.DataRow["Date"].ToString() == Date.InnerText.ToString()) 
         { 
         HtmlSpan chk = FindControl<HtmlSpan>(x => 
         { 
          x.Add(HtmlSpan.PropertyNames.Id, "timeMaterialGrid0_ctl0" + i + "_TriStateChkB"); 
          x.Add(HtmlSpan.PropertyNames.TagName, "SPAN"); 
         }); 
         Mouse.Click(chk); 
         break; 
         }    
        i++;   
      } 
+0

Verwenden 'return;' Anweisung statt 'brechen;' – FiN

+4

Put Stützpunkt auf der 'Bruch' Anweisung und Debug-Code. Ist der Debugger dort gestoppt? –

+0

Ich glaube nicht, dass die Rückgabe funktioniert, wie es in einer Lambda-Anweisung ist. Ziehen Sie in Erwägung, eine zusätzliche Methode für diesen Fall zu erstellen oder gotos zu verwenden. – MetaColon

Antwort

-1

Bitte lesen Sie meine Antwort unten, auch check this documentation über C# break-Anweisung zu erinnern.

int i = 2; 

foreach (UITestControl con in uIItemCustom.GetChildren()) 
       { 

        Description = new HtmlCell(con); 
        Description.FilterProperties[HtmlCell.PropertyNames.ColumnIndex] = "4"; 
        Date = new HtmlCell(con); 
        Date.FilterProperties[HtmlCell.PropertyNames.ColumnIndex] = "5"; 

       if (TestContext.DataRow["BillableLine"].ToString() == Description.InnerText.ToString() && TestContext.DataRow["Date"].ToString() == Date.InnerText.ToString()) 
         { 
         HtmlSpan chk = FindControl<HtmlSpan>(x => 
         { 
          x.Add(HtmlSpan.PropertyNames.Id, "timeMaterialGrid0_ctl0" + i + "_TriStateChkB"); 
          x.Add(HtmlSpan.PropertyNames.TagName, "SPAN"); 
         }); 
         Mouse.Click(chk); 
         break; 
         } 
      // This is the part you need to add - an else and break 
else{ 
    break; 
}    
        i++;   
      } 
+0

bro, das Inkrementieren funktioniert nicht, wenn wir so kodieren ... die ich nicht erhöht ... – user7755725