Category: LINQ

Convert foreach loop to Linq code

Converting this code to Linq: 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… } } […]

Read more

Check if property is null in lambda expression

  _approved = doa.getEmployee(new Guid(_guidid)).Where(m => !string.IsNullOrEmpty(m.Comment)).ToList(); Favorite

Read more

Single lambda expression

What is better to have two where clauses with && or just one where clause: //two where clause: list.Where(x => x.Prop1 == value1).Where(x => x.Prop2 == value2).ToList(); Or //one where clause with && list.Where(x => x.Prop1 == value1 && x.Prop2 == value2).ToList(); It’s better to use the &&¬†with two tests in a single lambda. It […]

Read more