Unable to change foreach to LINQ syntax
In Linq
some reserved word like Where
, FirstOrDefault
create a condition for your query and the Select
reserved word can create your object that you want the Select
method applies a method to elements. It is an elegant way to modify the elements in a collection such as an array. This method receives as a parameter an anonymous function—typically specified as a lambda expression.
Example: Let's look at a program where the Select extension method is applied to a string array. A local variable of array type is allocated and three string literals are used. We use Select on this array reference.
The basic method are here:
public static System.Collections.Generic.IEnumerable<TResult> Select<TSource,TResult> (this System.Collections.Generic.IEnumerable<TSource> source, Func<TSource,int,TResult> selector);
Now! for this issue that you searched for that you can use of this code:
var divNotaResult = list .Select((data, index) => data.FindElement(By.Id("accion-1-celda-0-" + index + "-0"))) .ToList();
In Select
method do like foreach
we have tow object in function
data and index.
The data
have each data in loop, and the index
have count of loop.