Locked how to iterate through foreach loop alternatively using c#

  • Friday, August 17, 2012 9:31 AM
     
     

    Hi,

    I have a code, where i need to iterate through the control alternatively

    code:

    List<string> allforms = new List<string>();

    HtmlControl control = new HtmlControl(this.uiTestObject);

    control.SearchProperties.Add(HtmlControl.PropertyNames.Class, "taskInfo");

    UITestControlCollection formsControls = control.FindMatchingControls();

    foreach(UITestControl x in formsControls)

    {

    HtmlCustom forms = (HtmlCustom)x;

    allforms.Add(forms.InnnerText);

    }

     

    I need to get the controls alternatively.How to iterate through the loop alternatively

    Plzzzzzzz help me on this

     

    Thanks in advance

All Replies

  • Friday, August 17, 2012 7:28 PM
     
     Answered Has Code

    Hi,

    You can use this approach if it helps:

    int decisionMaker = 1;
    foreach(UITestControl x in formsControls)
    {
      if(IsOdd(decisionMaker))
      {
       //do your stuff here for odd iterations
      }
      
      if(IsEven(decisionMaker))
      {
       //do your stuff here for even iterations
      } 
      decisionMaker++;
    }

    Where IsOdd or ISEven will be your methods to test for Odd/Even numbers.

    Regards,

    Pankaj


    Utility to run CUIT Ordered Tests for multiple iterations (Now with automated result mailing) @ http://cuitbatchrunner.codeplex.com/

  • Monday, August 20, 2012 4:21 AM
     
     

    Thank u for the reply

     

    Im getting error when i give "IsOdd" and "IsEven" methods

    are they user defined methods??

  • Monday, August 20, 2012 3:26 PM
     
     Answered

    Hi Divya,

    IsEven() and IsOdd() will be user-defined methods. you can search for these methods and I am sure you will get a lot of them.

    Regards,

    Pankaj


    Utility to run CUIT Ordered Tests for multiple iterations (Now with automated result mailing) @ http://cuitbatchrunner.codeplex.com/