You can also create a custom collection by inheriting from Dictionary(Of TKey, TValue)
Public Class BalanceDict Inherits Dictionary(Of String, Balance) Public Shadows Sub Add(ByVal bal As Balance) MyBase.Add(bal.BalDate & "|" & bal.AcctNum, bal) End Sub Public Shadows Function TryGetValue(ByVal balDate As Date, ByVal acctNum As String, <OutAttribute()> ByRef bal As Balance) As Boolean Return MyBase.TryGetValue(balDate & "|" & acctNum, bal) End Function End Class
I do not think that the speed difference between the complex key and the concatenated string is significant. With a composite key, you do not need to convert the date to a string; however, you will have to compute different hash codes and combine them. However, using a specialized dictionary implementation, you can hide the implementation data and decide to change the key generation method at any time without affecting other parts of your program.
source share