2009-12-01 97 views
1

我想將VB.NET字典對象擴展爲不在關聯數組中已經存在的項目。自定義字典對象?

這就是我想要做的:

Public Class BetterDictionary 
    Inherits System.Collections.Generic.Dictionary(Of Object, Object) 

    Public Sub Store(ByRef key As Object, ByVal value As Object) 
     If Me.ContainsKey(key) Then 
      Me(key) = value 
     Else 
      Me.Add(key, value) 
     End If 
    End Sub 

End Class 

我現在的問題是:我怎麼能代替行(對象,對象),讓詞典是通用/自定義類型的?

回答

3

定義你的繼承類爲:

Public Class BetterDictionary(Of TKey,TValue) 
    Inherits System.Collections.Generic.Dictionary(Of TKey, TValue)