以下是引用狐狸爸爸在2010-12-7 23:13:00的发言:
那就比较一下这两段吧
第一段:
Dim v As Double
For Each dr As DataRow In DataTables("表A").DataRows
v = DataTables("表A").Compute("Count(第二列 )", "第二列 = " & dr("第一列"))
dr("第四列") = v
Next
第二段:
Dim Dic As new Dictionary(of DataRow, Integer)
Dim v As Double
For Each dr As DataRow In DataTables("表A").DataRows
v = DataTables("表A").Compute("Count(第二列 )", "第二列 = " & dr("第一列"))
dic.Add(dr, v)
Next
For Each dr As DataRow In dic.Keys
dr("第四列") = dic(dr)
Next
對比上面的代碼效率時,第一段用時 0.35秒 ; 第二段用時 0.37秒
對比第一頁 一樓的代碼效率時,第一段用時 235.08秒 ; 第二段用時 0.8秒
不懂,怎麼會這樣...