Reputation: 123
Some days ago I asked for a way to find columns with null values in a row list with Linq. Now I need to get the index of every found item and add it to a list and then show in a warning message later.
These are my row list and my null columns list.
var rowList = tablaExcel.AsEnumerable().Select(x => x.ItemArray).ToList();
var nullValues = rowList.Where(x => x.Any(y => y == null || y == DBNull.Value)).ToList();
How can I get the index of any found item in the rowList.Where()? Just in case, I need the index of the rowList item, not of the nullValues item.
Thanks in advance.
Upvotes: 1
Views: 1397
Reputation: 6086
use this code:
var indexes = rowList.Select((v, i) => new { v, i })
.Where(x => x.v.Any(y => y == null || y == DBNull.Value))
.Select(x => x.i);
Upvotes: 1