Parallel ForEach on DataTable

前端 未结 5 1123
北荒
北荒 2020-12-04 19:27

I would like to use the new Parallel.ForEach function to loop through a datatable and perform actions on each row. I am trying to convert the code below:

           


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 19:50

    This is better than the accepted answer because this does not need to reference System.Data.DataSetExtensions:

     Parallel.ForEach(dt.Rows.Cast(), dr =>
    

    To use ForEach with a non-generic collection, you can use the Cast extension method to convert the collection to a generic collection, as shown in this example.

提交回复
热议问题