Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert foreach loop to linq code

Tags:

c#

linq

the below code is working as expected but I'm looking to convert the below code to use Linq? any suggestions?

       string[] selections = "Men,Women,Boys".Split(',');           

        int _chkboxId = 0;  
        int _chkboxTextId = 1;
        try
        {
            string id = "lstchk_" + _chkboxId;
            while (!driver.FindElement(By.Id(id)).Equals(null))
            {
                string checkboxId = String.Format("lstchk{0}", _chkboxTextId);
                string checkboxName = driver.FindElement(By.Id(checkboxId)).Text;

                foreach (string match in selections)
                {
                    if (checkboxName == match.Trim())
                    {
                        //matched... do more work here...
                    }
                }
           }

1 Answers

foreach (string match in selections.Where(match => checkboxName == match.Trim()))
{
    //matched... do more work here...
}
like image 152
Ofer Zelig Avatar answered Sep 23 '26 01:09

Ofer Zelig



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!