I would like to access the row number in linq query. There are many articles on the web stating how to do this but there is a catch: I want to resolve the enumeration "later" and I want it to assign the same ID every time. For this reason methods such as this do not work:
public IEnumerable<MyClass> GetThings(List<object> lst)
{
int ID=0;
return from i in lst
select new MyClass(ID++, i);
}
public class MyClass
{
public MyClass(int ID, object Stuff)
{ ... }
}
...
var x = GetThings(SomeList);
(fails because each time you resolve x by iterating each item gets a different id)