【发布时间】:2011-07-26 09:50:51
【问题描述】:
有没有更有效的方法来编写这段代码?
For Each row As DataRow In dt.Rows
Dim ts1 As String = row(0).ToString
For index As Integer = 1 To 9
Dim colName As String
colName = dt.Columns(index).ToString
For Each row2 As DataRow In dtAppAvail.Rows
Dim colName2 As String
Dim ts2 As String
colName2 = row2("Day").ToString.Substring(0, 3) & " " & CType(row2("Date"), Date).ToString("dd/MM")
ts2 = row2("Timeslot").ToString
If colName = colName2 AndAlso ts1 = ts2 Then
row(index) = row2("AppointmentsBooked")
End If
Next
Next
Next
【问题讨论】:
-
有效吗?慢吗?您是否有理由寻求提高效率?
-
过早的eje..优化是万恶之源。
-
它很慢,因为有很多 for 循环 - 试图减少它以使其更紧凑?
-
我会研究 LINQ 来解决这个问题而无需循环。
-
如果您的 DataRow 由数据库填充,我建议您执行特定查询以获取所需信息。
标签: vb.net optimization loops .net-2.0 performance