Is there a way in a for each to get the row index ?
Example :
int rowIndex = 0;
foreach (int a in numbers)
{
// Manipulation
rowIndex++;
}
What I would like to have
foreach (int a in numbers)
{
a.RowIndex;
}
Is there a quick way of doing it ? Maybe with the use of extension methods ?
Try the following
There is an overload of select which passes down the index of the item. This code will create a new anonymous type for every item which includes both the index and the value.
Here’s an alternate way which makes the syntax slightly more readable.
This doesn’t add a whole lot over the define a local and increment it manually solution. Is there a particular reason you don’t want to do it that way?