How To Project a Line Number Into Linq Query Results

前端 未结 5 1482
栀梦
栀梦 2020-11-27 14:04

How can I project the row number onto the linq query result set.

Instead of say:

field1, field2, field3

field1, field2, field3

I would like:<

5条回答
  •  粉色の甜心
    2020-11-27 14:44

    List Lstemp = GetEmpList(); 
    int Srno = 0; 
    var columns = from t in Lstemp 
                  orderby t.Name 
                  select new { 
                      Row_number=++Srno, 
                      EmpID = t.ID, 
                      Name = t.Name, 
                      City = t.City 
                  };
    

提交回复
热议问题