LINQ: Add RowNumber Column

前端 未结 9 1107
广开言路
广开言路 2020-11-29 07:26

How can the query below be modified to include a column for row number (ie: one-based index of results)?

var myResult = from currRow in someTable
                    


        
9条回答
  •  余生分开走
    2020-11-29 07:46

    Just for fun, here's an alternative to Select with two arguments:

    var resultsWithIndexes = myResult.Zip(Enumerable.Range(1, int.MaxValue - 1),
                                          (o, i) => new { Index = i, Result = o });
    

提交回复
热议问题