c# - Get index of lines that match my linq -
i have linq statement , know if possible indicies of lines match statement? here is:
var result = list3.where(middle => list4.any(x => x == middle.middle.category1)).select(obj => new { obj, dt = datetime.parseexact(obj.leftcolumn, dateformat, cultureinfo.invariantculture) }) .where(x => x.dt >= datetimepickerchoice1 && x.dt <= datetimepickerchoice2) .select(x => x.obj).tolist();
you can use overload of select
(or where
) projects index of element:
var result = list3.select((middle, index) => new{ middle, index }) .where(x => list4.any(xx => xx == x.middle.middle.category1)) .select(x => new { x.middle, x.index, dt = datetime.parseexact(x.middle.leftcolumn, dateformat, cultureinfo.invariantculture) }) .where(x => x.dt >= czas11 && x.dt <= czas22) .select(x => x.index) .tolist();
side-note: consider change variable names more meaningful. unreadable.
Comments
Post a Comment