我想使用新的Parallel.ForEach函數來遍歷數據表,並對每一行執行操作。我想下面的代碼轉換:Parallel ForEach on DataTable
foreach(DataRow drow in dt.Rows)
{
...
Do Stuff
...
}
要將此代碼:
System.Threading.Tasks.Parallel.ForEach(dt.Rows, drow =>
{
...
Do Stuff
...
});
當我運行新的代碼中,我得到的錯誤:
的方法的類型參數「系統.Threading.Tasks.Parallel.ForEach(System.Collections.Generic.IEnumerable,System.Action)'不能從使用情況中推斷出來。嘗試明確指定類型參數。
這是什麼正確的語法?
D'oh!擊敗拳頭(僅僅幾秒)! – JaredReisinger 2010-08-04 18:31:09
這個擴展是否可用於實現IEnumerable的其他集合?如TreeNodeCollection?或者我必須自己創建這個擴展名? – 2010-11-12 12:29:56
@Scott:你必須自己編寫它 - 因爲否則它不會知道返回哪種類型的'IEnumerable',如果你明白我的意思。 –
2010-11-12 21:54:34