How to get the row number from a datatable?

前端 未结 7 1438
谎友^
谎友^ 2020-12-08 06:18

I am looping through every row in a datatable:

foreach (DataRow row in dt.Rows) {}

I would like to get the index of the current row within

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-08 07:01

    int index = dt.Rows.IndexOf(row);
    

    But you're probably better off using a for loop instead of foreach.

提交回复
热议问题