Accepted answer
ienumerable<priorelemst> priorselemlst =,i) => new priorelemst(s, priorslstdates[i]));
return filterstudypriors(priorselemlst);


it is not a best practice at all but only if you think it will improve the readability against a performance loss.

linq-to-objects generally is going to add some marginal overheads (multiple iterators, etc). it still has to do the loops, and has delegate invokes, and will generally have to do some extra dereferencing to get at captured variables etc.

is a linq statement faster than a 'foreach' loop?


you can use the zip method

var priorselemlst =
    priorslstdates, (i, d) => new priorelemst(i, d))

in the above statement i is the item from priorslstids and d the item from priorslstdates. they will be 'zipped' together using their positions in their lists.


you could use the enumerable.range method like so:

//first get the range of indexes
var range = enumerable.range(0, priorslstids.count);
//now project a list of elements at each index
var priorselemlst = => new priorelemst(priorslstids[i], priorslstdates[i])).tolist();

Related Query

More Query from same tag