假设我们有一个
Dictionary(Of Date, List(Of SomeClass))
我们在数据库中有大约一百万行,所以我很好奇哪一个在性能方面更好,检查我的字典是否有键,或者直接在 try catch 子句中添加而不检查它?
While Reader.Read
Try
MyDictionary.Add(Reader("SaleDate"), New SomeClass(Reader("SaleData")))
Catch ex As Exception
' Silence here
End Try
End While
While Reader.Read
Try
If Not MyDictionary.ContainsKey(Reader("SaleDate")) Then
MyDictionary.Add(Reader("SaleDate"), New SomeClass(Reader("SaleData")))
End If
Catch ex As Exception
MsgBox("ERROR")
End Try
End While