c# - DataTable check if row is last in collection -
say have datatable so:
state of d dataviewrowstate.deleted , lets o rows have not been touched
index: 0 | state: o index: 1 | state: o index: 2 | state: o index: 3 | state: d index: 4 | state: d say delete row @ index 2 (i set row state deleted). there way know if row @ index 1 last non-deleted row in collection without "walking forward" , checking rows state of each record after index 1?
you can use linq:
int deletedindex = 2; datarow firstnondeletedbeforedeletedindex = table.asenumerable() .where((row, index) => index < deletedindex && row.rowstate != datarowstate.deleted) .lastordefault(); // null if none found
Comments
Post a Comment