How do you add an index field to Linq results

Don’t use a query expression. Use the overload of Select which passes you an index:

var list = FileList.Select((file, index) => new { Index=index, Filename=file });

Leave a Comment