score:8

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

score:2

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?

score:4

you can use the zip method

var priorselemlst = priorslstids.zip(
    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.

score:4

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 = range.select(i => new priorelemst(priorslstids[i], priorslstdates[i])).tolist();

Related Query

More Query from same tag