自定义字典对象?

时间:2009-12-01 08:26:56

标签: vb.net inheritance dictionary

我想扩展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

我现在的问题是:如何替换(对象,对象)行以使字典具有通用/可自定义类型?

1 个答案:

答案 0 :(得分:3)

将继承的类定义为:

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