reversed foreach loop
Posted: Mon Apr 22, 2013 3:09 pm
Hi folks,
Any idea how can I do reversed foreach loop? I have a code like this...
If the foreach loop is done in a normal order (1, 2, ....n), the tabs are closed but not all of them, because the tabPageList Count is not decreased. So I soon have less tabs, than is the initial count of all tabs and the actual loop index does not match with actual tab index. This is why I need to start closing the tabs in reversed order (5, 4,...1).
I tried to use this code (found about "Reverse" via google):
Sorry for a silly question, I'm a C# noob
Any idea how can I do reversed foreach loop? I have a code like this...
foreach (Ranorex.TabPage tab in tabPageList) { tab.Click(); Report.Screenshot(repo.LB.Self); Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'LB.TabPage' at .462;.462.", repo.LB.TabPageInfo); tab.Click(new Location(TabPage_Screenshot1, "Center", TabPage_Screenshot1_Options)); }Basically, the code enumerates available "tabs" in program, click each tab (to make its [x] button visible), take a screenshot and click the tab's [x] button. And here comes the problem.
If the foreach loop is done in a normal order (1, 2, ....n), the tabs are closed but not all of them, because the tabPageList Count is not decreased. So I soon have less tabs, than is the initial count of all tabs and the actual loop index does not match with actual tab index. This is why I need to start closing the tabs in reversed order (5, 4,...1).
I tried to use this code (found about "Reverse" via google):
foreach (Ranorex.TabPage tab in tabPageList.Reverse())But it seems it does not work. Any idea how to make the "Reverse" working?
Sorry for a silly question, I'm a C# noob