Wednesday, May 2, 2012

How do you add an index field to Linq results

Lets say I have an array like this:



string [] Filelist = ...


I want to create an Linq result where each entry has it's position in the array like this:



var list = from f in Filelist
select new { Index = (something), Filename = f};


Index to be 0 for the 1st item, 1 for the 2nd, etc.



What should I use for the expression Index= ?





No comments:

Post a Comment